Parse JS user is not persistent, after i close the ionic app user not logged in


#1

Need help, was using Parse JS SDK along with Ionic framework. As longi did not close the app my user is logged in, once close the app my user is logged out automatically. Couldn’t figure out why


#2

Did u look at my parse starter implementation? I believe it maintains the current user.


#3

Parse is really difficult with ionic because it uses a different frameworks object model. I would recommend using their REST API and the cloud code. Not only does it play really nice with angulars http methods, but you can write all the API logic in cloud code and it’s more secure because the user can not edit it.

There are a lot of resources and I know they have been improving their docs


#4

Thanks a lot for the reply, can you guys look at my code on where i did wrong? https://github.com/joevo2/paradise_mystery_shopper/blob/master/www/js/controllers.js

okay @aaronksaunders i will look into it once I’m free thanks a lot for replying :wink:

@NorthMcCormick look at the REST api seems to be very complicated for me this newbie :frowning: what else other backend as a service would u recommend? Parse is making my work a lot easier but they doesn’t really officially support ionic :frowning: but there is a lot of tutorial around the web though :slight_smile:


#5

The REST is actually the easiest way because you don’t have to deal with an API that isn’t supported like you just said.

Parse is the easiest that it gets, I haven’t ever come across anything more simple unfortunately. Back ends for apps are always a little bit complicated


#6

Thanks for the tips :slight_smile: gonna try using the rest API, but where should i start? what i saw in the parse documentation about REST is all those curl and stuff :frowning: no idea how to use it :frowning: curl is linux-ish stuff right to download or get site or something


#7

CURL is the example. You have to make the call using angular $http provider. There are hundreds if not thousands of tutorials online for it.


#8

The JavaScript SDK is the way to go, you just need to patch your objects to support property get/set instead of the method based get()/set()

Here’s the code snippet you need:

var contactMessageFields = ['user', 'message']
var ContactMessage = Parse.Object.extend({
    className : "ContactMessage",
    attrs : contactMessageFields
})

enhance(ContactMessage.prototype, contactMessageFields)

function enhance(prototype, fields) {
    for (var i = 0; i < fields.length; i++) {
        (function() {
            var propName = fields[i]
            var proto = prototype
            Object.defineProperty(proto, propName, {
                get : function() {
                    return this.get(propName)
                },
                set : function(value) {
                    this.set(propName, value)
                }
            })
        })()
    }
}

Also check out https://github.com/brandid/parse-angular-patch/


#9

Im sorry i couldnt really understand the snippet as i just started with ionic with no prior knowledge of angular. I need to pickup angular seriously… I just hacking my way with JS and programming knowledge and exp :frowning: gonna try the parse-angular-patch seems to ber very interesting :smiley: thanks a lot


#10

Im so sorry, i followed https://github.com/brandid/parse-angular-patch/2 and did bower install but it doesnt seems to work. when i include the ‘parse-angular’ my ionic app doesnt work, checked the log says that it couldnt find the file. How should i actually properly install this :frowning:

i checked with creating a new app, same problem. The parse-angular patch is install in the lib folder but when i inculde it in the angular module like this,

angular.module(‘starter’, [‘ionic’, ‘starter.controllers’,‘parse-angular’])

it doesnt work at all


#11

Did you add a script tag to your index.html to load the parse-angular module?


#12

Thanks a lot! added and it seems to work nicely, i should use the parse-angular-patch/dist/parse-angular.js instead of parse-angular-patch/src/parse-angular.js right?

But my user doesn’t seems to work just yet. https://github.com/joevo2/paradise_mystery_shopper/blob/dev/www/js/controllers.js


#13

I kinda fixed my problem by putting the parse initialise in the controller.js instead of the app.js