Firebase 验证邮件 React

Firebase verification email React

尝试用firebase做一个登录系统。当我注册时,数据存储firebase并给我验证邮件,它没用。当我确认然后数据存储 firebase 时,我需要先给我邮件。如果我不能使用验证,它完美地工作,完美地存储数据并且工作正常。当我使用验证时它给我电子邮件并同时存储数据它不等待我的确认..

const SignUp = () => {


    const [user, setUser] = useState({

        isSignIn: false,
        name: '',
        email: '',
        password: '',
        confirmPassword: '',
        error: '',
        passwordError: '',
        success: false


    })


    //check function  password  & confirm password equal or not 

    const isPasswordConfirmed = (password, confimPassword) => {

        if (password && confimPassword && password === confimPassword) return true;
        return false;
    }


    const handleSubmit = (event) => {
        event.preventDefault()

        if (!isPasswordConfirmed(user.password, user.password_confirm)) {

            let newuser = { ...user }
            newuser.passwordError = "password not matching"
            setUser(newuser)

            return;
        }

    //   user.sendEmailVerification()
               
      



      const newname=  firebase.auth().createUserWithEmailAndPassword(user.email, 
 user.password)
    
         
            .then((userCredential) => {
                // Signed in 

              
               
                var user = userCredential.user;
                
                 user.sendEmailVerification()  //mail verification firebase 
              
                let newuser = { ...user }
                newuser.error = ""
                
                setUser(newuser)

                // UserInfoPass(user.name)

                // ...
            })
            
            .catch((error) => {
                var errorCode = error.code;
                var errorMessage = error.message;
                user.isSignIn = false

                let newuser = { ...user }
                newuser.error = errorMessage
                setUser(newuser)




            });



    }

这在之前经常提到:Firebase 身份验证在用户登录之前不需要电子邮件验证。相反,您可以在您的应用程序代码中检查用户的验证状态(包括前端代码、后端代码、以及 Firebase 的安全规则),以确保他们只有在验证了电子邮件地址后才能使用该应用程序。

或者,您可以use an email link to sign in将电子邮件验证和身份验证合并到一个步骤中。

有关此内容的更多信息,请参阅:

  • How to check if Firebase user's email is verified before signing in to React web app
  • Is there a way to verify a signed up email?

还有更多 search