gpt4 book ai didi

firebase - 向现有用户发送验证电子邮件

转载 作者:行者123 更新时间:2023-12-04 08:08:09 25 4
gpt4 key购买 nike

我正在开发具有现有用户群的网络应用程序。电子邮件验证最初并未在登录流程中实现。
我已经成功添加了用于为所有新注册发送验证电子邮件的代码,但我还想制作一个小页面(或模式),其中将向当前用户显示一个按钮,将验证链接发送到他们的收件箱
我使用 createUserWithEmailAndPassword 创建用户的当前注册流程我能够访问 user.user.sendEmailVerification方法这样做,但找不到任何方法来访问此方法来为现有用户实现该功能。
有没有办法访问 sendEmailVerification 创建用户后的方法?

I am assuming that it would be available within the onAuthStateChange trigger but implementing that would lead to a bad UX (as I do not want to prompt the users everytime they login)


编辑:
我知道文档说明我们可以使用 firebase.auth().currentUser获取当前用户,但由于某种原因不起作用。
另外,我发现了 references网上建议不再使用该方法,他们提到使用 onAuthStateChange方法代替,这就是为什么我正在研究这种方法

最佳答案

你可以试试这个方法:

const btnVerifyEmail = document.getElementById("btn-verify-id")
btnVerifyEmail.onclick = function () {
const user = firebase.auth().currentUser;

user.sendEmailVerification().then(function() {
// Email sent.
console.log("Email Sent")
}).catch(function(error) {
// An error happened.
console.log(error)
});
}
它在文档中提到 here

关于firebase - 向现有用户发送验证电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66114853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com