[英]Prevent login when using createUserWithEmailAndPassword in Firebase
I want to avoid automatically login after using createUserWithEmailAndPassword with React and Firebase.我想避免在将 createUserWithEmailAndPassword 与 React 和 Firebase 一起使用后自动登录。 is that possible?
那可能吗? Here is my code.
这是我的代码。 Thanks a lot.
非常感谢。
const SignUp = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [displayName, setDisplayName] = useState("");
const [error, setError] = useState(null);
const createUserWithEmailAndPasswordHandler = async (event, email, password) => {
event.preventDefault();
try{
const {user} = await auth.createUserWithEmailAndPassword(email, password);
generateUserDocument(user, {displayName});
const test = user.emailVerified;
console.log("Verified: ",test,);
}
catch(error){
setError('Error: ... '+error);
};
setEmail("");
setPassword("");
setDisplayName("");
user.sendEmailVerification({url: process.env.REACT_APP_CONFIRMATION_EMAIL_REDIRECT="https://...my url.........."});
console.log('Email is not verified ');
alert("email confirmation sent");
};
When you create an account, that account is automatically signed in. There is no way to prevent this.创建帐户时,该帐户会自动登录。没有办法阻止这种情况。
The two most common reasons for asking this are:问这个问题的两个最常见的原因是:
To prevent the user from using the app until they have verified their email address.防止用户在验证其电子邮件地址之前使用该应用程序。 In that case, you have two options.
在这种情况下,您有两个选择。
Because your app's user is an application administrator who is creating accounts for other users.因为您的应用程序的用户是为其他用户创建帐户的应用程序管理员。
This is not a supported use-case in the client-side SDKs for Firebase, as such account creation should be done server-side through the Admin SDK .这不是 Firebase 客户端 SDK 中受支持的用例,因为此类帐户创建应通过Admin SDK在服务器端完成。
If you insist however, you can work around this limit by creating a secondary FirebaseApp
instance to create the user, as shown here .但是如果你坚持,你可以通过创建一个辅助解决此限制
FirebaseApp
实例来创建用户,如图所示这里。
I'll add some links in a moment...稍后我会添加一些链接...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.