2

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!!!' });
    }
}
KENdi
  • 7,205
  • 2
  • 14
  • 26
Parth Nandaniya
  • 75
  • 2
  • 14

1 Answers1

0

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.
dilix
  • 3,510
  • 3
  • 27
  • 53
  • 1
    actually i want to somthing like this: 1) register with email and password 2) email link verification 3) when email verify, user can login with email and password they provided. So there is two auth. one is email and password and another is email verification, so how can i archive that – Parth Nandaniya Jul 28 '18 at 13:37