6

I'm building a Meteor + Cordova app where I want sign-in to "stick forever" on the mobile device.

I see the following tutorial whereby I can setup my own custom "resume handler"

I'll probably write my own (janky) implementation of the above functions and try to get it working, probably storing in localStorage on the client... but I thought I'd ask here to see if anyone knew of a specific solution to this wrapped as package, or a clean example.

Ideally:

  • meteor add xxxxx:rememberme
  • setup
    • rememberMe.config.days = 9999
    • rememberMe.config.storageClient = localStorage

NOTE: this is related to Meteor Accounts autologin pattern?

Recommendations?

Community
  • 1
  • 1
zeroasterisk
  • 2,199
  • 1
  • 23
  • 28

2 Answers2

4

How about using the built-in Accounts.config(options) http://docs.meteor.com/#accounts_config

Accounts.config({
   loginExpirationInDays: null
}) 

Once logged in, it will never expire until the user logout again with Meteor.logout();

However, be aware that since the token is stored in localstorage, it get cleaned sometimes automatically by iOS or android

Green
  • 4,950
  • 3
  • 27
  • 34
  • The "getting cleared out automatically" is what I remember hearing about -- Any way around that? Anyway - this is the "right" way, I just don't know how to keep it from getting cleared out. – zeroasterisk Sep 24 '14 at 13:11
  • 2
    I dont think it's possible to control the localstorage cleanup by OS. On the other hand, you can make use of the file system api http://plugins.cordova.io/#/package/org.apache.cordova.file . I suppose you can save the token in a file as a backup. So you will normally read the token from localstorage, if the token is not there due to clean up, you can read it from the file. – Green Sep 24 '14 at 13:32
  • That sounds like a great solution... I'll look into it - thanks! – zeroasterisk Sep 24 '14 at 19:44
  • can you tell me more about the localstorage cleanup by OS... if I were to switch to say WebSQL, would it still get trashed periodically? – zeroasterisk Sep 25 '14 at 02:19
  • 1
    There is a bug apparently (at the time of writing) why this solution won't work anymore, see https://github.com/meteor/meteor/issues/5121 – pors Oct 06 '15 at 17:18
3

This mbanting:cordova-accounts-resume package will help resolve this by saving the loginToken on the file system, to be used if localStorage is cleared out before the app resumes.

Mart
  • 31
  • 1