2
votes

I am new to React and I am attempting to implement a persistent state for sessions using firebase for a personal project. I currently have within the auth.js file:

export const sessionState = (email, password) => {
  auth.setPersistence(auth.Persistence.SESSSION)
  .then(() =>
  auth.signInWithEmailAndPassword(email, password)
)};

But it's still loading with a local state persistence, I've looked at the documentation: https://firebase.google.com/docs/auth/admin/manage-sessions and https://firebase.google.com/docs/auth/web/auth-state-persistence

1
You have to put the return no ? - GameTag
I initially tried that following the documentation, but it fails to compile on my local machine. - Question_Everything
SESSION should save the Auth state in sessionStorage. Check sessionStorage to confirm. - bojeil

1 Answers

0
votes

From the perspective of a Firebase app, the session of your app is driven by the authentication state of the user. If there is no authentication in use at all, then your app will be 100% responsible for that, i.e. localstorage or cookies.

So, in the Firebase's model, the .onAuthStateChanged observer should drive the initialState and state of your component.