簡體   English   中英

如何從 firebase 身份驗證 onCreate 觸發器中獲取用戶的哈希密碼和哈希鹽?

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

我正在嘗試使用 onCreate 身份驗證觸發器訪問用戶的散列密碼和散列鹽,但我總是得到 null 值,但是我正常獲取其他用戶的值。

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

為什么會這樣?

如果您閱讀這些屬性的定義,它會說:

  1. 如果未設置密碼,則為 null。
  2. 這僅在從listUsers()獲取用戶時可用。

是否使用電子郵件密碼身份驗證創建新用戶? 即使是,該user object 也會將這些值設為 null。 您可以在以下 Github 問題中了解更多信息:

為什么 passwordHash 和 passwordSalt 僅適用於 listUsers()?


如果您還想將用戶的密碼存儲在 Firestore 中,那么您可以在 Cloud Function 本身中創建用戶:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM