How to keep user logged in so they don't have to always log back in when they open app.

+1 vote
I was testing Parse out last week before I discovered App42 Cloud and one thing I liked about it was that once a user logged in, they stayed logged in unless you specifically logout.  So when the user opens the game again, they are already logged in.  This was built in and automatic, so I don't know how they did it.  I guess they cached the username and password and logged them in as soon as the game started.

How could I achieve this with App42 Cloud?  I'm using Unity.  I know I could save the username and password in PlayerPrefs and log them in that way, but is that a good idea?  It seems like that may not be a good way to do it, especially saving the password like that.  How would you accomplish this?
asked Apr 9, 2014 in App42 Cloud API-BaaS by Rhinosaurus (32 points)

1 Answer

+2 votes
 
Best answer
This can be easily done with App42 also by saving sessionId in PlayerPrefs. You will get sessionId of user after authentication of user in User object by calling getSessionId method on it. On logout just remove this sessionId from PlayerPrefs.

On openening of the app just check if sessionId is there or not, if not open the login page otherwise app landing page.

We will include this in  our SDK too in upcoming release.

Ajay Tiwari

App42 Platform
answered Apr 10, 2014 by ajay123 (899 points)
selected Apr 10, 2014 by Rhinosaurus
Thanks!  That will work very well.  After I get the sessionid from player prefs, what do I do with it to be able to restore that User object?

I think for my purposes if I also save the userName in PlayerPrefs, then create a new User object, and set the userName and sessionId based on what is saved in player prefs it will work.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...