James N
James N

Reputation: 533

local storage being wiped in ionic on iOS and android

I am making a mobile app w/ a rails server for the backend. The basic premise is when a user signs in successfully, the server returns a unique token and their user_id. I store only those 2 things in local storage (window.localStorage not any library)

localStorage.setItem('user_id', data['id']); localStorage.setItem('authToken', data['auth_token']);

I then use the token/ID to communicate with the server.

The problem, is recently in testing (app is already live w/ a couple dozen users), the token is occasionally not getting set or saving, and as a result, I get a 500 error. I say occasionally because sometimes it does work. I guess I'm mainly just confused. It was working fine w/ my initial pushes on the app, and works on ionic view. I don't know what has changed, as I have not changed any code.

From my standpoint and in my initial debugging, it looks like local storage is either unreliable, i need to use an angular/ionic option (not window.localStorage), find another way to store data like I have been (SQLite?), or it could be a permissions bug?

If anyone has experience something similar to this and found a viable solution, I would love to learn more about this and find a solution to fix it.

Upvotes: 0

Views: 450

Answers (1)

Diogo Machado
Diogo Machado

Reputation: 429

I think that before you choose another data store option, you must see your application in execution, try inspect the app in Google Chrome inspect or in Safari (case iOS), look at the localStorage proprieties using your app, I believe this is enough for you do fix your bug.

Inspect Chrome: https://developers.google.com/web/tools/chrome-devtools/remote-debugging/

Inspect Safari: http://phonegap-tips.com/articles/debugging-ios-phonegap-apps-with-safaris-web-inspector.html

Upvotes: 2

Related Questions