alyssaxuu / mapus

A map tool with real-time collaboration 🗺️
MIT License
3.32k stars 202 forks source link

When I refresh the page, I log out #4

Closed dislazy closed 2 years ago

dislazy commented 2 years ago

When I refresh the page, I log out, which feels that the experience is not very good

alyssaxuu commented 2 years ago

Hmm, this could be due to this. I noticed there seems to be some inconsistencies where sometimes it will keep you logged in on refresh, and sometimes not. It appears it could have something to do with a delay when loading firebase, it might check when it's not ready yet. You could try increasing the timeout there to see if it works. Ultimately I'm not sure what the fix would be, I'd have to look into it further.

dislazy commented 2 years ago

Hmm, this could be due to this. I noticed there seems to be some inconsistencies where sometimes it will keep you logged in on refresh, and sometimes not. It appears it could have something to do with a delay when loading firebase, it might check when it's not ready yet. You could try increasing the timeout there to see if it works. Ultimately I'm not sure what the fix would be, I'd have to look into it further.

Okay, thank you very much, I wonder if it is possible to store the session in localstorage

403-Fruit commented 2 years ago

I think this is caused by this line:

// Make sure the session persists after closing the window so the user doesn't have to log in every time
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)

In the firebase docs, firebase.auth.Auth.Persistence.SESSION is described as

Indicates that the state will only persist in the current session or tab, and will be cleared when the tab or window in which the user authenticated is closed

I think firebase.auth.Auth.Persistence.LOCAL is the right setting:

Indicates that the state will be persisted even when the browser window is closed or the activity is destroyed in React Native. An explicit sign out is needed to clear that state. Note that Firebase Auth web sessions are single host origin and will be persisted for a single domain only

I've created a pull request with this change here: https://github.com/alyssaxuu/mapus/pull/5