Moo Zhen Cong
Moo Zhen Cong

Reputation: 29

React Native check user email with sendEmailVerification after createUserWithEmailAndPassword is perform

I have given a task to code about sending email verification to user after they have registered themselves in signup screen which is react native based. Create new user is handle in one js file called AuthProvider.js. In one of the return value of AuthContext.Provider, there is one action which handle create new user which is shown code below and is working fine.

    registerWithEmail: async (userDetails) => {
                        const { email, password } = userDetails;
    
                        return await auth()
                            .createUserWithEmailAndPassword(email, password)
                            .then(() => {
                       //wish to add on the send email verification action here
                                return true;
                            });
                    }

The return true code above is used to do checking in signup screen. If I wish to return the true value only if the condition where verification email is send to them and is clicked. How can I do it and can I have any kind of guidance?

Upvotes: 2

Views: 5191

Answers (2)

Dharmaraj
Dharmaraj

Reputation: 50840

You can use async-await syntax with `try-catch this way.

registerWithEmail: async (userDetails) => {
  try {
    const { email, password } = userDetails;
    const {user} = await auth().createUserWithEmailAndPassword(email, password)
    await user.sendEmailVerification()
    return true
  } catch (e) {
    console.log(e)
    return false
  }

It'll return true only when the email is sent. If there's any error in the function it'll trigger catch and the function will return false.

Upvotes: 3

Qadir Ali
Qadir Ali

Reputation: 58

I don't know more about react-native but in android studio when we send verification email and when user clicked on it. We have firebase function to check user clicked on verification link or not.

  FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

        if (user.isEmailVerified())
        {
            // user is verified, so you can finish this screen or send user to other screen which you want.

        }

i hope it will help you and give you some idea...

Upvotes: 0

Related Questions