How to stay logged in and preserve local storage after user closes app?

I have implemented a HTTP auth sign up/login utilizing JSON Web Tokens (https://github.com/sahat/satellizer) where the token is saved in local storage after authentication. However, I have discovered after I emulate and build the app on my iPhone, go ahead and login, and then close the app, the user’s login session is destroyed.

Is local storage preserved when a user closes the app? Have I made a possible oversight in my technical implementation? How can I go about keeping a user logged in once they’ve closed the app?

3 Likes

In these link most options describes, which might help to you.

If you want to use local storage then used as follow.
set variable in your login controller with local storage and if you want them used in entire application then defined such variable in factory file.

Set Local storage variable :

localStorage.setItem("var_1",value1);
localStorage.setItem("var_2",value2); and so on.

Get variable value in app.js file and check whether the login details like username, password, auth token and other information available or not :

localStorage.getItem("var_1");
localStorage.getItem("var_2"); and so on.

2 Likes

Maybe you’re using sessionStorage instead of localStorage. sessionStorage is cleared after app closes.
http://docs.phonegap.com/en/3.0.0/cordova_storage_storage.md.html#localStorage

In both cases it is a good pratice wrap it in a service then future changes on Storage won’t impact so much :smile:
https://gist.github.com/rcbytes/0f977e56c6e6da146b35

–Edit-- @jrschumacher

Or if you want something complete, my 2 cents:

1 Like

There are a number of AngularJS wrappers around localStorage. My goto:

http://ngmodules.org/modules/ngStorage

2 Likes