在 .then() 内完成注册后,我一直试图将用户重定向回“/”或“/home”,但除重定向外,promise 中的所有内容都执行失败。我只使用 if(true) 来测试它,它确实到了那个点,因为我可以让 console.log 在那里显示文本,但只是重定向是徒劳的..
const createUserWithEmailAndPasswordHandler =(event) => { event.preventDefault();
auth.createUserWithEmailAndPassword(signUp.email, signUp.pw1).then((authData) =>{
console.log("authData" + authData);
addUserDataToDb({
email: signUp.email,
username: signUp.username,
});
if (true) {
return <Redirect to='/home' />;
}
})
.catch((error) => {
setSignUp({
...signUp,
error: error,
});
console.error(error);
});
setSignUp(INITIAL_STATE);
}