hyperneutrino
hyperneutrino

Reputation: 5425

Firebase AUTH won't stay logged in

When I log into a firebase app using signInWithEmailAndPassword(email, password), the user is logged in. Then, if I reload the page, the user is no longer logged in. If I go to another webpage with the same firebase apiKey and everything, the user still isn't logged in. How would I go about making sure the user stays logged in until firebase.auth().signOut() is called?

Upvotes: 2

Views: 3387

Answers (1)

hyperneutrino
hyperneutrino

Reputation: 5425

Simply using firebase.auth().currentUser usually won't work because when that's loaded, Firebase usually hasn't authenticated and connected a user account yet. Instead, wait for the authorization state to change using firebase.auth().onAuthStateChanged(func) where func is called when the auth state is changed (which could mean signing in or signing out or switching accounts).

Upvotes: 8

Related Questions