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 ( 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?


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_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_2"); and so on.


Maybe you’re using sessionStorage instead of localStorage. sessionStorage is cleared after app closes.

In both cases it is a good pratice wrap it in a service then future changes on Storage won’t impact so much :smile:

–Edit-- @jrschumacher

Or if you want something complete, my 2 cents:


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