在 firebase auth 中,只有在将用户电子邮件设置为登录的主要电子邮件后,我才能验证用户的电子邮件。 我可以这样更改用户电子邮件:
var user = firebase.auth().currentUser;
user.updateEmail("user@example.com").then(function() {
// Update successful.
}).catch(function(error) {
// An error happened.
});
这样设置后我就可以验证电子邮件了:
var user = firebase.auth().currentUser;
user.sendEmailVerification().then(function() {
// Email sent.
}).catch(function(error) {
// An error happened.
});
我想要做的是在将电子邮件设置为用户的主要电子邮件之前验证电子邮件。
最佳答案
是的,只有在验证后您才能更改电子邮件。 API 没有很好的文档记录。您可以通过verifyBeforeUpdateEmail来完成.
firebase.auth().currentUser.verifyBeforeUpdateEmail('newEmail@example.com')
.then(function() {
// Verification email sent.
/ When the user clicks the email link,
// it will update to newEmail@example.com and set it as verified,
// emailVerified: true.
// Until then, the old email remains on the account.
})
.catch(function(error) {
// Error occurred. Inspect error.code.
});
关于javascript - 如何在将电子邮件设为主要电子邮件之前对其进行验证(Firebase 身份验证),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61535850/