ground-db icon indicating copy to clipboard operation
ground-db copied to clipboard

Half logged out state when grounding Meteor.users

Open itaibs opened this issue 8 years ago • 5 comments

Hi! This problem is a bit elusive, so I'll try to bring enough information so we could perhaps figure it out:

In my app all users sign in using accounts-facebook. It's vital for my app to keep working and have the user's data when offline, so I'm grounding Meteor.users:

if (Meteor.isClient) {
    Meteor.startup(() => {
        Ground.Collection(Meteor.users);
    });
}

Sometimes, however, when connected to the server, I see that while everything seems to be working ok - the user "seems" to be logged out (i.e., gives a "sign in with facebook" button). I can't quite figure out exactly what causes this and when this happens - but I think it's usually after the user disconnects from the server and reconnects.

If I exit the app and reenters it just becomes connected and signed in again (all becomes OK). I also have some callback registered on "Hooks.onLoggedOut" which never gets called - so the system doesn't know that the user has logged out (because he really didn't log out).

It's really hard to debug since I can't reproduce this problem manually. It just sometimes happens. My guess is that it has to do with some conflict in the grounded Meteor.users. Does that sound reasonable? Any idea how I can go about trying to handle this?

Thanks! Please tell me if you need more info...

itaibs avatar Apr 12 '16 09:04 itaibs

Same error here too.

I have the normal username password login, On my Android / IOS apps if the apps were terminated when user is logged in and reopened the logged in status is gone. The user is not there anymore.

But if I terminate the app again and reopen it, I see the user is logged in. this is weird. @raix

sahanDissanayake avatar May 01 '16 04:05 sahanDissanayake

If it helps the discussion, I ended implementing my own fix, saving the user's information locally and not grounding Meteor.users anymore. It wasn't easy (since I need to take care of all the synching between Meteor.user() and my own locally saved data manually), but it did fix the issue. I don't see this problem anymore.

itaibs avatar May 01 '16 09:05 itaibs

Care to share some code please ?

sahanDissanayake avatar May 01 '16 09:05 sahanDissanayake

I'd love to, but it's not a simple workaround that I can find a specific piece of code that "did the trick" and paste it here.

Basically, I created a local persistent session variable "localUser" and used a Tracker.autorun to make it synced with Meteor.user(). To address the specific needs of my app, I then also had to add some cases where I want this sync not to happen (e.g., when the user is disconnected from the internet), remember a logout action if it happened when the user was offline, etc. It's really very specific and it's made of code going around many different places in my client codebase.

Sorry :/

itaibs avatar May 01 '16 09:05 itaibs

Have you tried 2.0.0-rc.3 (mind the new patterns)

raix avatar May 01 '16 13:05 raix