React Native
...
Parse SDK (REST)
Users

Email Verification

11min

User email verification for React Native

Introduction

Having a mobile app with unrestricted user registration can cause security issues and spam in your application server. Email verification can help you prevent this situation, requiring that any registered user on your app will have a valid email address.

In this guide, you will learn how to set up email verification in your Back4App server, which will automatically handle this verification. You will also learn how to make sure in your application that the user is indeed verified.



At any time, you can access the complete Android Project built with this tutorial at our Github repositories

Goal

To build a User LogIn feature using Apple Sign-in on Parse for a React Native App.

Prerequisites

To complete this tutorial, you will need:

1 - Configure Email Verification

You will now configure your Parse Server on Back4App to require user email verification. Open your Back4App dashboard and navigate to your server settings control panel. Find the Verification emails feature and click on Settings:

Document image


Go ahead and check the Verify User Emails and Prevent login if email is not verified checkboxes. Feel free to update and customize any settings in this screen, like the verification email message body and reply-to address.

Document image


After setting this up, your Parse server instance will now handle user email verification automatically.

Note: Activating Prevent login if email is not verified is not required, but it is good practice to require your new users to verify before performing any action in your app.

2 - Update your UserRegistration component

You need to make some changes in your UserRegistration component to correctly sign up users with email verification. First, add a new input field for your user’s email value. Update the user registration function in the UserRegistration.js (UserRegistration.tsx if you are using TypeScript) file so now you are setting the email attribute on user data:

UserRegistration.js
UserRegistration.tsx


Note that since your user is not supposed to login without verifying his email, you need to log him out after registration to avoid any errors in the current application Session. Test your application and now you should see a message like this after registering a new user:

Document image


After successfully registering your new user, Parse will send an email containing a verification link, looking like this:

Document image


3 - Set up your UserLogIn component

Your Parse server is now blocking automatically login attempts that are not from verified users. However, it’s also a good practice to make sure that there is no way for your unverified user to access your application, so let’s add a new condition inside your UserLogIn component in the UserLogIn.js (UserLogIn.tsx if you are using TypeScript) file:

UserLogIn.js
UserRegistration.tsx


4 - Test the email verification

Go ahead and test your application, trying to log in using the unauthorized user created before. If you didn’t click the verification link on the email, you should get an error message like this:

Document image


After clicking on the verification link, you will be able to log in and be redirected to your home screen. You can also verify your user by opening your Users table inside your Back4App dashboard and editing the emailVerified column manually:

Document image


Conclusion

At the end of this guide, you learned how to set up your Parse server to require user email verification and also to enforce this restriction inside your React Native application. In the next guide, we will show you how to perform useful user queries.