Firebase Detecting if user exists

后端 未结 4 993
天涯浪人
天涯浪人 2021-01-11 12:16

How Can I Check user exists in Firebase auth in Signup Button via react native?

This is my Login Page Code:

export de         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 12:32

    For me fetchSignInMethodsForEmail() only works with an email that is registered with email/password and not working for emails registered with Apple, LinkedIn or other providers.

    For solution to this, I came up with following work around:

    auth().signInWithEmailAndPassword(email, 'some-random-password')  // Password should be really long to avoid actually logging in :)
    .then((response) => {
        // TODO : Avoid this block
    })
    .catch((error) => {
        if(error.code === 'auth/wrong-password'){
            // TODO : If here then it means account already exists...
        }
    
        if(error.code === 'auth/user-not-found'){
            // TODO : If here then you guessed it... you can create a new account.
        }
    })
    

    I'm sure there is a proper solution for this and I will update this answer when I find it.

    Hope this will help someone

提交回复
热议问题