AliOz
AliOz

Reputation: 485

How to get a user's hashed password and hashed salt from firebase authentication onCreate trigger?

I am trying to access a user's hashed password and hashed salt using onCreate authentication trigger but I always got null values for both of them, however I am getting the other user's values normally.

exports.savePasswordsInfo = functions.auth.user().onCreate((user) => {
  functions.logger.log("hash: ",user.passwordHash);
  functions.logger.log("salt: ",user.passwordSalt);
  functions.logger.log(user)
});

Why is that happening?

Upvotes: 1

Views: 1250

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50910

If you read the definition of those properties, it says:

  1. If no password is set, this is null.
  2. This is only available when the user is obtained from listUsers().

Are the new users created using email-password auth? Even if yes, that user object will have those values as null. You can read more about this in the following Github issue:

Why is passwordHash and passwordSalt only available with listUsers()?


If you want to store user's password in Firestore as well then you can create the user in a Cloud Function itself:

exports.createUser= functions.https.onCall((data, context) => {
  // 1. Read user email and pass from data
  // 2. Store the information in Firestore
  // 3. Create a user in Firebase Auth
});

Upvotes: 1

Related Questions