如何从 firebase 身份验证 onCreate 触发器获取用户的哈希密码和哈希盐?
How to get a user's hashed password and hashed salt from firebase authentication onCreate trigger?
我正在尝试使用 onCreate 身份验证触发器访问用户的散列密码和散列盐,但我总是得到它们的空值,但是我正常获取其他用户的值。
exports.savePasswordsInfo = functions.auth.user().onCreate((user) => {
functions.logger.log("hash: ",user.passwordHash);
functions.logger.log("salt: ",user.passwordSalt);
functions.logger.log(user)
});
为什么会这样?
如果您阅读这些属性的定义,它会说:
- 如果没有设置密码,则为空。
- 只有从
listUsers()
获得用户时才可用。
新用户是使用email-password auth创建的吗?即使是,该 user
对象也会将这些值设为 null。您可以在以下 Github 期中阅读更多相关信息:
Why is passwordHash and passwordSalt only available with listUsers()?
如果您还想将用户密码存储在 Firestore 中,那么您可以在 Cloud Functions 本身中创建用户:
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
});
我正在尝试使用 onCreate 身份验证触发器访问用户的散列密码和散列盐,但我总是得到它们的空值,但是我正常获取其他用户的值。
exports.savePasswordsInfo = functions.auth.user().onCreate((user) => {
functions.logger.log("hash: ",user.passwordHash);
functions.logger.log("salt: ",user.passwordSalt);
functions.logger.log(user)
});
为什么会这样?
如果您阅读这些属性的定义,它会说:
- 如果没有设置密码,则为空。
- 只有从
listUsers()
获得用户时才可用。
新用户是使用email-password auth创建的吗?即使是,该 user
对象也会将这些值设为 null。您可以在以下 Github 期中阅读更多相关信息:
Why is passwordHash and passwordSalt only available with listUsers()?
如果您还想将用户密码存储在 Firestore 中,那么您可以在 Cloud Functions 本身中创建用户:
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
});