我正在尝试弄清楚,当现有的身份验证用户试图更新他们的电子邮件地址时,是否有办法从Firebase Auth发送验证电子邮件。我想在实际调用'user.updateEmail(newEmail)‘之前这样做,这样如果他们出于某种原因不应该使用该电子邮件地址,它实际上不会更改他们在Firebase Auth中的电子邮件登录。
它看起来不像'sendEmailVerification‘方法允许手动提供一个电子邮件地址来验证。
理想情况下,我希望这样做:
//User provides a newEmailAddress for their account
//Send verification email to the newEmailAddress
//User verifies newEmailAddress
user.updateEmail(newEmailAddress) is executed有没有一种很好的方式通过Firebase Auth来做到这一点呢?
发布于 2019-07-17 07:01:17
对于此流,Firebase身份验证中没有内置任何内容。
如果你有自己的电子邮件服务器,你绝对可以实现它。但是,您需要习惯于生成自己的随机数、发送电子邮件,并拥有一个端点来处理电子邮件中的点击。
发布于 2021-05-12 05:28:45
实际上有一种方法。您需要设置continueUrl并调用verifyBeforeUpdateEmail,这会将用户重定向到您的应用程序。DynamicLink将包含验证流程所需的信息,之后您可以调用updateEmail。
发布于 2021-10-21 06:07:07
2021年10月
使用verifyBeforeUpdateEmail方法绝对可以做到这一点。
示例(Javascript):
firebase.auth().currentUser
.verifyBeforeUpdateEmail('user@example.com')
.then(function() {
// Verification email sent.
// Clicking the link in email will update the email address.
})
.catch(function(error) {
// Error occurred. Inspect error.code.
});^以上代码就是您需要的全部代码。
但是,您还可以传递一个可选的第二个参数actionCodeSettings。当此参数出现时,状态/继续URL将被设置为电子邮件验证链接中的"continueUrl“参数。
示例(Javascript):
const actionCodeSettings = {
url: 'https://www.example.com/cart?email=user@example.com&cartId=123',
iOS: {
bundleId: 'com.example.ios'
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12'
},
handleCodeInApp: true
};
firebase.auth().currentUser.verifyBeforeUpdateEmail(
'user@example.com', actionCodeSettings)
.then(function() {
// Verification email sent.
})
.catch(function(error) {
// Error occurred. Inspect error.code.
});Firebase Docs
https://stackoverflow.com/questions/57066173
复制相似问题