0

I am using the 'accounts-base' and 'accounts-password' packages and the Accounts.createUser method to create users from a login form (i.e. I am not using the accounts-ui package).

the documentation explains that the user thus created includes a 'services' object

"containing data used by particular login services. For example, its reset field contains tokens used by forgot password links, and its resume field contains tokens used to keep you logged in between sessions."

This is true and accounts created using my login form all have loginTokens. However, when I refresh the browser, these tokens are deleted and the user is logged-out.

The documentation appears to suggest that resume tokens are handled automatically by the accounts-base / accounts-password packages. What have I missed?

Accounts.createUser({
      username: username,
      email: username,
      password: password
    }, function (err) {
      if (err) {
        alert(err)
      } else {            
        Router.go('/member/' + Meteor.userId() +'/edit')               
      }
    });

creates:

 "resume" : 
{ "loginTokens" : 
  [
   {
   "when" : ISODate("2014-04-17T22:13:50.832Z"),
   "hashedToken" : "KstqsW9aHqlw6pjfyQcO6jbGCiCiW3LGAXJaVS9fQ+o=" 
   } 
  ] 
}

...but on refresh:

"resume" : { "loginTokens" : [ ] } },
Alex Webster
  • 707
  • 1
  • 6
  • 21
  • `Accounts.createUser` is a server function. How are you accessing the `Router.go` client function in a callback? Mind where you are placing your code... – Andrew Mao Apr 18 '14 at 03:21
  • According to the [documentation](http://docs.meteor.com/#accounts_createuser), Account.createUser is available on both client and server. I am using it on both, for different puposes, but the effect, so far as this question is concrened, is the same: the user is successfully created, the tokens are created, but refreshing the page in the browser logs out the user and deletes the tokens. I confess that I am unclear as to what is supposed to happen, but suffice it to say I don't want the user to be logged out when the page is refreshed, for whatever reason. – Alex Webster Apr 18 '14 at 04:43

1 Answers1

1

After an exhaustive audit of my code I found that I was (idiotically) invoking the Accounts.logout method outside the confines of the log-out button event. It had somehow become 'orphaned' during an earlier re-factoring of the code

So all my fault.

Alex Webster
  • 707
  • 1
  • 6
  • 21