Reputation: 29
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
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
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