简体   繁体   English

firebase:如何链接电子邮件验证和密码

[英]firebase: how to link email verification and password

I already authenticate user with email and password, but I want to add email link verification using firebase in react native. 我已经使用电子邮件和密码对用户进行身份验证,但是我想在React Native中使用Firebase添加电子邮件链接验证。

So, user have to provide right email address that he/she owned and password, how can I link them or create it. 因此,用户必须提供他/她拥有的正确的电子邮件地址和密码,如何链接或创建它们。

This is my code for signup: 这是我的注册代码:

export const signupUser = ({firstName, lastName, userName, email, password}) => async dispatch => {
    dispatch({ type: SIGNUP_SPINNER });
    try {
        let user = await firebase.auth().createUserWithEmailAndPassword(email, password);
        if(user) {
            const { currentUser } = firebase.auth();
            // add displayName 
            await currentUser.updateProfile({
                displayName: `${firstName} ${lastName}`
            });
            await firebase.database().ref(`/users/${currentUser.uid}/profile`)
                .push({firstName, lastName, userName, email})
                .then(async () => {
                    dispatch({ type: SIGNUP_INITIAL_STATE });
                });
        }
    } catch(err) {
        dispatch({ type: SIGNUP_USER_FAIL, payload: 'something went wrong, please try again!!!' });
    }
}

The email verification could be done in several ways in mobile apps: 电子邮件验证可以在移动应用程序中以多种方式完成:

  1. let user to login via native account attached to the phone ( https://github.com/react-native-community/react-native-google-signin ). 让用户通过手机附带的本机帐户( https://github.com/react-native-community/react-native-google-signin )登录。 If user able to login via google means that he's a legal user of the account 如果用户能够通过Google登录,则表示他是该帐户的合法用户
  2. Send email ( Sending automated emails from Firebase through Google Cloud Platform (no third parties) ) with link like https://yourserver.com/?token= and activate the email if user opens this link. 发送具有https://yourserver.com/?token=之类的链接的电子邮件( 通过Google Cloud Platform从Firebase发送自动电子邮件(无第三方) ),如果用户打开此链接,则激活电子邮件。 In this case you need your own script on the server. 在这种情况下,您需要在服务器上拥有自己的脚本。
  3. Send email ( Sending automated emails from Firebase through Google Cloud Platform (no third parties) ) with link like yourScheme://verification?token and handle this scheme on your device and veridy the account by endpoint. 发送带有yourScheme:// verification?token之类的链接的电子邮件( 通过Google Cloud Platform从Firebase发送自动电子邮件(无第三方) )并在您的设备上处理此方案,并通过端点验证该帐户。 It's less secure but you don't need your server. 它的安全性较差,但不需要服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM