Narendra Kumar
Narendra Kumar

Reputation: 91

How to get user info from email in firebase

I am using bcryptjs and nodejs along with firebase, and facing problem in login. The userinfo (along with hashed password) is getting stored in firebase database (sign-up is working fine), to compare the entered password (by user) with stored password, I am using below method -

bcrypt.compare(req.user.password, user.password, function(err, res) {
   // res === true
});

ref: https://www.npmjs.com/package/bcryptjs

I need userinfo from the entered emailid, but I am stuck here, couldn't retrieve userinfo from firebase as userinfo is mapped to uid, not email.

Can I get userinfo from user entered email id (from firebase), or some other way to authenticate user.

Thanks.

Upvotes: 0

Views: 763

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599876

Since you tagged with node.js: in a trusted environment you can use the Firebase Admin SDK to look up users by their email:

admin.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);
  });

Upvotes: 1

Related Questions