Skip to content
Advertisement

How can I check if user exists in Firebase?

I finally got my authentication to work in terms of creating users and logging in and out. But now, I want to implement something that checks if the user already exists in Firebase. I’ve looked it up but can’t seem to find a concrete answer.

For example, if my email address is: abc12@gmail.com and someone else tries to signup with the same email address, how do I tell them it’s already taken?

JavaScript

Advertisement

Answer

The error that is returned from method createUserWithEmailAndPassword has a code property. Per the documentation the error code auth/email-already-in-use:

Thrown if there already exists an account with the given email address.

At very minimum you can utilize conditional statements such as if/else or switch to check for that code and display/log/dispatch/etc a message or code to the user:

JavaScript

Hopefully that helps!

Advertisement