Meteor Accounts Resume Token "Remember Me"
Asked Answered
T

2

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?

Tellurite answered 12/9, 2014 at 1:43 Comment(0)
R
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

Rutty answered 24/9, 2014 at 6:22 Comment(5)
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.Tellurite
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 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.Rutty
That sounds like a great solution... I'll look into it - thanks!Tellurite
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?Tellurite
There is a bug apparently (at the time of writing) why this solution won't work anymore, see github.com/meteor/meteor/issues/5121Millibar
B
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.

Betti answered 8/8, 2015 at 0:52 Comment(1)
Thanks for that. This is the answer that will actually work on all devices.Millibar

© 2022 - 2024 — McMap. All rights reserved.