简体   繁体   English

在 Firebase 中使用 createUserWithEmailAndPassword 时防止登录

[英]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:问这个问题的两个最常见的原因是:

  1. To prevent the user from using the app until they have verified their email address.防止用户在验证其电子邮件地址之前使用该应用程序。 In that case, you have two options.在这种情况下,您有两个选择。

    1. Use a passwordless email link to sign the user in. With this flow, the user's email address is automatically verified before they are signed in.使用无密码电子邮件链接让用户登录。通过此流程,用户的电子邮件地址会在登录前自动验证。
    2. Check whether the user's email address is verified before allowing them to use the app, and access its data.在允许用户使用应用程序和访问其数据之前,检查用户的电子邮件地址是否经过验证。 You'll do this both in the client-side application code , to control the navigation there, and in the server-side application code , or server-side security rules , to ensure the user can't access data they're not authorized for.您将在客户端应用程序代码中执行此操作以控制那里的导航,并在服务器端应用程序代码服务器端安全规则中执行此操作,以确保用户无法访问未经授权的数据为了。
  2. Because your app's user is an application administrator who is creating accounts for other users.因为您的应用程序的用户是为其他用户创建帐户的应用程序管理员。

    1. 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在服务器端完成。

    2. 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.

相关问题 Firebase身份验证-createUserWithEmailAndPassword()-在验证电子邮件之前禁止登录 - Firebase Auth - createUserWithEmailAndPassword() - prevent login until email is verified Firebase 使用 createUserWithEmailAndPassword 后看不到用户 - Firebase cannot see user after using createUserWithEmailAndPassword 在javascript和firebase中使用“ createUserWithEmailAndPassword(电子邮件,密码)”时如何获取用户ID - How to take user Id when using “createUserWithEmailAndPassword(email, password)” in javascript and firebase 用于createUserWithEmailAndPassword的Firebase和Captcha - Firebase & Captcha for createUserWithEmailAndPassword Firebase createUserWithEmailAndPassword上的超时连接 - Timeout connection on firebase createUserWithEmailAndPassword Firebase createUserWithEmailAndPassword未在登录时授权用户 - Firebase createUserWithEmailAndPassword not authorizing user on sign in Firebase onAuthStateChanged干扰createUserWithEmailAndPassword.then - Firebase onAuthStateChanged interfers createUserWithEmailAndPassword.then Firebase 身份验证为 createUserWithEmailAndPassword 返回未定义 - Firebase Auth returning undefined for createUserWithEmailAndPassword 使用 React 在 Firebase 中的 createUserWithEmailAndPassword 上添加用户名 - Add username on createUserWithEmailAndPassword in Firebase with React Firebase 在 React 应用程序中验证 createUserWithEmailAndPassword - Firebase Auth createUserWithEmailAndPassword in React app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM