I'm merging an ionic app from firebase v2 to firebase v3.
When I use the new (v3) firebase email/password login API, I am not authenticated have to log in every time the app is re-started.
The user should stay authenticated when first logged in into the app. Or at least this was default in the firebase v2 API.
How can I persist the login?
Thanks, Jørgen
You should use onAuthStateChanged(). This function will be called any time there's a change in the authentication state.
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
... do other stuff
} else {
// No user is signed in.
... do other stuff
}
});
If you are already logged in when you open your app, or you call signInWithEmailAndPassword, this function will be called and user will contain firebase.auth().currentUser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With