React Native - Firebase auth persistence not working -
firebase auth not persist logged in user , everytime refresh or reopen app have sign in again.
i have tried setting persistence local , callback verify set persistence still no working
for setting persistence using...
//set auth persistence firebase.auth().setpersistence(firebase.auth.auth.persistence.local) .then(function() { console.log("successfully set persistence"); }) .catch(function(error){ console.log("failed ser persistence: " + error.message) });
. . . signing in using code
firebase.auth().signinwithemailandpassword(email, password) .then((user) =>{ this.checkaccountstatus(user.uid, user.email); }) .catch(function(error) { // handle errors here. var errorcode = error.code; var errormessage = error.message; console.log(errormessage) // ... });
and here code using check login status...
if (firebase.auth().currentuser) { const currentuser = firebase.auth().currentuser; console.log("signed in username" + currentuser.displayname); this.props.navigation.navigate('apptab'); }else{ console.log("no user signed in"); this.props.navigation.navigate('authtab'); }
if there not doing right
you don't need set persistence. firebase handles default. need call function check whether user logged or not:
firebase.auth().onauthstatechanged((user) => { if (user) { console.log('user logged'); } }
this not triggered if user has sign out or cleaned app data.
you can find more details in official docs: https://firebase.google.com/docs/auth/web/manage-users
hope helps.
Comments
Post a Comment