IOS logout from device every day, localStorage data gets cleared

I have implemented localstorage to store token and personal user information but in ios devices I gets logout everyday because token gets cleared form localstorage.

Hi akhilesh2310,

Your provided information is so much basic. It would be good if you provide exact steps or detailed information of the issue. Or you can share some piece of code here.

.state('app.posts', {
                    url: '/posts',
                    views: {
                        'menuContent': {
                            templateUrl: 'templates/posts.html',
                            controller: 'PostCtrl'
                    onEnter: function ($state) {
                        var token = localStorage.getItem("token");
                        if (!token) {

I am using above code to check token from localStorage but every day I get logout from device as I found out token is not available in localstorage. SO I need to login again and after 1 day or after few hours when I open app again I get logout.

Logout means I got to landing screen. and no information is available inside localstorage.

This issue occurs in iphone only.

Can you also mention the code where you are setting the local storage?


Also according to iOS localstorage persistence this discussion it is always good to use other libraries like ngStorage for the localstorage persistency.

iOs deletes localStorage when a device is low on storage. Look into other solutions like pouchDB of WebSQL :slight_smile:

I am setting token after api response using this code

var token = res.headers("Authorization");
if (token) {
         localStorage.setItem("token", token);

Syntax looks perfect to me. So strange why its not letting you persist the data in it.

I would also recommend to you to go with ngStorage plugin in ionic rather than following standard HTML5 localstorage.

If it is feasible for you then you can also go with sqllite option too.

@akhilesh2310 we are experiencing a very similar issue. Local storage is frequently cleared on devices with low memory. Since auth data is stored in local storage, which is wiped out, the user is then forced to log out.

What did you end up doing to resolve this issue?