Home > Net >  How does google chrome save my authenticated user even after I refresh the page?
How does google chrome save my authenticated user even after I refresh the page?

Time:02-15

So I am making a firebase web app and I am authenticating the user at the moment. When the user signs in, it takes them to a brand new page and refreshes the page. I was told that when you refresh the page all the memory is cleared.

What I don't understand is somehow chrome saves the user even after I refresh the page. So the current user stays logged in even though the memory should have been cleared.

How does chrome do this? Shouldn't I have to log my user into firebase again after the user refreshes the page? It just doesn't make sense how the user is still logged in even though the page is refreshed and the memory was cleared. I would just like more information on what exactly is going on.

CodePudding user response:

When the user signs in, the Firebase Authentication SDK stores the (encoded) user credentials in the local storage of the user's browser.

When you (re)load the page, the SDK restores the user's authentication state from that information in local storage.

This does require it to call to the server though (a.o. to check if the account was disabled in the meantime), so to pick up when the credentials have been restored use an auth state listener.

  • Related