Gregivy / simpleddp-plugin-login

Meteor.Accounts login plugin for simpleDDP
MIT License
12 stars 5 forks source link

User Logout when page refreshed #1

Closed abhirakshit closed 5 years ago

abhirakshit commented 5 years ago

Hello,

I have a Vue project which I am connecting with my Meteor server. I am seeing a weird issue that after a page refresh both the "server.userId" and "server.token" fields become undefined and the server throws logged out exception on method calls.

I have tried to manually set these fields after persisting the fields locally in the vue store. Is there some kind of setting I am missing which is causing this behavior.

Regards,

Gregivy commented 5 years ago

Hello!

You don't miss anything. This plugin does not save userId or token in storage, because it is supposed to be universal for node, browser or something else.

And you are free to make your own saving policy by that. For example you can use browser's localStorage for that. You can save token and if there is a a token being saved in localStorage do the code bellow before anything else on page load:

let token = localStorage.getItem('token');
...
try {
  await server.login({resume:token});
} catch (e) {
  // failed auth by token
}

Or you can make something more complex and save username, password, use plugin's events like loginResumeFailed when auto-resume has failed and etc.

abhirakshit commented 5 years ago

Thanks a lot. This works for me as I am already storing the user auth data in the Vue store.