【发布时间】:2021-01-06 16:25:51
【问题描述】:
我只是在用 react js 和 firebase 制作一个简单的单页应用程序。在认证中,部分用户可以使用邮箱和密码创建一个新账户,但要先登录,他们需要验证他们的邮箱。
我的代码。
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((authuser) => {
if (authuser){
setuser(authuser);
}
else{
setuser(null);
}
});
return () => {
unsubscribe();
}
},[user,username]);
const signup = (event) => {
event.preventDefault();
var user = auth.createUserWithEmailAndPassword(email,password)
.then((authuser) => {
authuser.user.updateProfile({
displayName : username
})
})
.catch((error) => {
alert(error.message);
}
);
user.then((authuser) => {
authuser.user.sendEmailVerification();
})
.then(() => {alert("We have send you an confirmation email to verify your account")})
.catch((error) => { return; })
.then(() => {handleClose()});
}
const signin = (event) =>{
event.preventDefault();
auth
.signInWithEmailAndPassword(email,password)
.then(() => {loghandleClose()})
.catch((error) => {alert(error.message)})
}
在创建新用户注册方法后跳过发送确认电子邮件部分,为什么用户在创建新帐户时会自动登录。 我认为 onAuthStateChanged() 功能会在新用户创建时自动运行,并跳过注册方法的发送确认电子邮件部分。
请问我该如何解决。
【问题讨论】:
标签: javascript reactjs firebase-authentication