Home > Back-end >  Firebase user signOut doesn't work in react native
Firebase user signOut doesn't work in react native

Time:03-24

I'm building an app and I'm handling the authentication with Firebase. The signIn create user functions work in the intended way, but for some reason, the signOut function doesn't work. When the button for the SignOut is clicked, the user should be signed out, but instead, he stays signed in

const signOutUser = () =>{
        console.log(authentication.currentUser.email)//before calling this is [email protected]
        signOut(authentication)
        .then((result) => {
            console.log(result)
        })
        .catch((error) => {
            console.log(error);
        })
        console.log("entered sign out functions")
        console.log(authentication.currentUser.email)//after above code runs this is till [email protected]
    }

Could somebody please advise what I'm doing wrong?

CodePudding user response:

const signOutUser = () => {
    console.log(authentication.currentUser.email);
    signOut(authentication).then((result) => {
        console.log(result);
        console.log("entered sign out functions");
        console.log(authentication.currentUser.email);
    }).catch((e) => { console.log(e) })
}

or

const signOutUser = async() => {
    // add try catch if you want
    console.log(authentication.currentUser.email);
    const result = await signOut(authentication);
    console.log("entered sign out functions");
    console.log(authentication.currentUser.email);
}

You should await the signOut or write your code in then(). If this is still not working, you probably made a mistake with your signOut(authentication) function.

  • Related