Firebase身份验证-手机身份验证忘记了密码

时间:2020-09-16 18:43:03

标签: swift firebase firebase-authentication

我的应用当前允许用户通过电话号码创建其Firebase帐户。我目前正在尝试弄清用户使用电话号码而不是电子邮件创建帐户时密码重置的逻辑。

我在Firebase文档上可以找到的唯一重置密码功能需要一个电子邮件地址。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您可以使用verifyPhoneNumber:UIDelegate:completion:向用户发送另一条SMS消息以进行验证,然后使用verificationID登录。

有关操作方法的官方文档-> https://firebase.google.com/docs/auth/ios/phone-auth#send-a-verification-code-to-the-users-phone

PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { (verificationID, error) in
  if let error = error {
    self.showMessagePrompt(error.localizedDescription)
    return
  }
  // Sign in using the verificationID and the code sent to the user
  // ...
}

OR

如果拥有服务器,则可以使用Node.js,Java,Python,Go和C#中可用的Firebase admin SDK来仅通过用户的uid来更新用户的密码属性。

Node.js中的示例:

admin.auth().updateUser(uid, {
  password: "YOUR_NEW_PWD"
})
  .then((userRecord) => {
    console.log('Successfully updated user', userRecord.toJSON());
  })
  .catch((error) => {
    console.log('Error updating user:', error);
  });