2
votes

I already authenticate user with email and password, but I want to add email link verification using firebase in react native.

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!!!' });
    }
}
1

1 Answers

0
votes

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). If user able to login via google means that he's a legal user of the account
  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. 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. It's less secure but you don't need your server.