Email Verification
This section explains how you can create an app with user registration and email verification using Parse Server core features through Back4App.
This is how it will look like:
At any time, you can access the complete Ionic Project built with this tutorial at our GItHub repository.
To complete this quickstart, you need:
- An app created at Back4App.
- Followed the User Registration tutorial to learn how to implement sign up, login and log out with back4app.
In this tutorial, we will be starting from where we left off in the previous User Registration one.
- Find the “Verification emails” block and click on Settings. The “Verification emails” block looks like this:
3. Click on Verify User Email. It is right here:
4. Fill in the empty fields and modify the ones that have already been filled based on your preferences.
5. Click on the SAVE button.
The two fundamental attributes of ParseUser class are username and password. There’s a third special attribute that you should also set, i.e. the email. To implement Sign Up with Email Verification, you will use the same method as the basic user registration. But this time, instead of sending the user to the Home page, you will ask him/her to verify his/her email to login.
Once the user creation is completed, it is automatically added to Parse Dashboard and its emailVerified Boolean attribute is set as false. At this point, the user should not be allowed to log into your platform. Once he/she verifies his/her e-mail, by clicking on the link sent to his/her mailbox, the emailVerified boolean will be automatically set to true, enabling him/her to access your platform entirely.
To make SignUpActivity work, follow these steps:
Add the isSigningup and email variables to login.ts to toggle and hold the e-mail input:
Make the signUp() method send the e-mail address to the parse User.signUp() function:
Now, let’s reflect those changes to the view login.html by adding *ngIf to show/hide html elements whenever the user is signing up (isSigningup is equal to true) or signing in (isSigningup is equal to false).
Now, let’s add the emailVerified boolean verification before sending the user to the Home page.
Note: Although the user logs in when the function Parse.User.logIn() is called, he/she can’t access the app until the e-mail verification is done. Also, because of a Session object is created in the database when calling logIn(), it’s important to call Parse.User.logout() every time a user who hasn’t verified his/her e-mail tries to access the application in order to not leave Sessions opened.
Now, let’s implement the emailVerified verification to decide whether the user logs in or get an alert saying e-mail must be verified:
- Test your app by running ionic serve and creating a couple of users, also try logging in after registering without verifying the email to see if the error is actually displayed.
- Find your app and click on Dashboard > Core > Browser > User to see the users that you’ve created!
At this stage, you can login, register or logout of your app using email verification with Parse Server core features through Back4App!