Pattern for storing credentials for mobile app?

I’d like to store credentials for my mobile app so that the user does not need to re-enter his credentials and re-authenticate when the app is restarted, whether it be because connection timed out or it crashes, the server restarted etc. Basically I’d like it to behave like facebook, twitter etc. apps I’m sure we all have on our phones. Is there a pattern to handle this with Meteor?

I was speculating that I could hack something with Phonegap’s localstorage but I don’t know if there is a known or better way.

Thanks in advance!

Meteor login should already persist through localstorage. Does it not work for you?

hi @sashko… if there is no network connectivity, the app does not switch to local storage… is this the expected behaviour?

The login state is always stored in localstorage, regardless of online state.

If the users device runs out of memory, it is possible that the local storage will be cleared, in this case you should use a Cordova plugin like nativestorage.

Actually I am looking at the use case when I close the mobile app and reopen it.

If there is no network access, my app simply cannot do the login for the user.

Is there some way to persist the auth in case there is no network available on restart of the app.

So you want to have offline access to your subscriptions and user data? Then you should use Ground:DB. We are using it for a messenger app, so the user can access all chats even if he is offline. He also stays “logged in”.

1 Like

Nice! When online, does it fetch first from local and then go online? So the application would appear fast…

Yes, it automatically syncs if the connection gets established.