Firebase Authentication : Lookup a user by Email
Solution 1
The new method of creating users with email password returns a value whether the given email address is already in use. See here
Solution 2
I use fetchProvidersForEmail(email) and if the result return as empty array then, this email hasn't been use to sign up.
firebase.auth().fetchProvidersForEmail(email)
.then(providers => {
if (providers.length === 0) {
// this email hasn't signed up yet
} else {
// has signed up
}
});
Solution 3
You can look up user information by email:
firebase.auth().getUserByEmail(email)
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully fetched user data:', userRecord.toJSON());
})
.catch(function(error) {
console.log('Error fetching user data:', error);
});
I'd like to make things more clear that this method does not exist — one could be looking for it in the firebase client library, in which it has never been available in the first place and it wouldn't be a good idea to have anyway. This method is part of the admin SDK, so in order to call the method, you need to run it on the server, and invoke it from the client. OP didn't scope the question to firebase client library, so my answer is still correct.
7hacker
Updated on June 05, 2022Comments
-
7hacker about 2 years
I am using Firebase Authentication with Email and Password
I would like to know if i can 'lookup' a user by email only while also not being signed in as a user
The reason I'd like to do this is, is to simply identify if I am already a user of the system, using an email address only
I looked at this older thread but it appears to be the previous version of Firebase
Is it possible to do this in the current Firebase, or my alternative would be to keep this information available (and open to all?) to find out if a given email is part of my system?
-
7hacker almost 8 yearsYup this is just what I needed! Thanks!
-
Greg over 4 yearsNote that the method is now called fetchSignInMethodsForEmail
-
Ruben Szekér about 3 yearsThe returned object's documentation can be found on the UserRecord reference documentation from firebase
-
Salathiel Genèse almost 3 yearsThis API does not exists [anymore].
-
samthecodingman almost 3 yearsThe method from these answers still applies, however how you access it in v9 onwards has changed: fetchSignInMethodsForEmail
-
Salathiel Genèse almost 3 yearsThis API tells us which providers can a user signs-in with... Not the user account infos, like, for name one, his profile URL.
-
Andrea almost 3 years@SalathielGenèse Where did you find mention to the API deprecation? I can still see it referenced here: firebase.google.com/docs/reference/admin/node/… and documented here: firebase.google.com/docs/auth/admin/…
-
Salathiel Genèse almost 3 yearsSorry @Andrea, you just called to my attention that JS vs. Dart SDK APIs differs with subtleties. Thank you.