user5809746
user5809746

Reputation:

Meteor Accounts - user disconnected after a page refresh

I currently have a problem with the implementation of Accounts Meteor. I've already made several research on the subject, but I find only vague information without get a real answer.

I implemented account-base and account-password and I manage the connection of the user with the method "loginWithPassword" (http://docs.meteor.com/#/full/meteor_loginwithpassword). No problem with this, the user connects, but when the page is refreshed (either with the browser button or refreshed compiling) the user is disconnected.

Do you know how to fix this or do you have ideas about where I can direct me?

Thanks you in advance for your answer.

Upvotes: 3

Views: 808

Answers (2)

digitalextremist
digitalextremist

Reputation: 5993

There is a delay, at pageload, before Meteor.user() has a value. That was the real issue in my case. It was too unstable to depend on Meteor.user() and a bit too tethered to the framework.

Not sure the UI framework was in use in the question a few years ago by the deleted account there, but this issue can be addressed in any modern one with a hook firing before render to wait for the token. But that is a bad idea, because then there is a delay on pageload.

My solution was to add a persistent store, and hold the initial successful return of Meteor.user() at login, and even have login take place from within an action of the persistent store.

Then you can watch for the server to invalidate the token and kill it in the store as well. And the token expiration can be used by the store to kill its credential on its own. But more importantly, on initial pageload, if you have a token, the persistent store provides a locally cached login.

It seems better to assume login if a credential is present, then wait to see if it was invalidated, versus assume no credential and wait to see if there is one, before rendering.

Upvotes: 0

Azaruddin Sherif
Azaruddin Sherif

Reputation: 33

I have been playing around with meteor for last few months and not sure 0f what i written below is relevant/appropriate.

Run this from Console after the page refreshes.

Meteor.user()

if you get an object that means you are still logged in. just to be sure you may explore the user object and look for services>>resume>>logintokens>>0>hashedToken.

if the above step is fine then check the status of ddp by running below

Meteor.status()

if everything is fine in here( i mean if it shows connected) then check for your routes..

Thanks.

Upvotes: 0

Related Questions