FIrebase auth: check if user exist before create new one with signInWithPopup()

Viewed 783

I want to add the ability for already registered users to log in using Facebook. I'm using signInWithPopup method with FacebookAuthProvider for this. But when user with the same email does not exist, Firebase creating the new user - what I don't need.

Can I somehow cancel the creation of a new user after successful login via Facebook, if I do not have a user with the same Email?

2 Answers

signInWithPopup will return a UserCredential object if everything went right. If you want, you can check the _tokenResponse property of the object, which itself is another object containing a property called isNewUser. As you might have guessed this property returns whether the currently signed-in user is a new user or not. If it's a new user you can delete the user via firebase.auth.currentUser().delete(), otherwise it's not a new user and you can handle it accordingly.

Related