Implementing User Email Verification in Open Event Frontend
Open Event Server provides the functionality of user email verification after a user registers, but it was not implemented on Open Event Frontend until recently. For users, this meant they were still not able to verify themselves, even after receiving confirmation links in their inboxes, which were sent by the server. Thus, implementing it on frontend was crucial for a complete user registration workflow.
Since the server had already exposed an endpoint to perform the registration, all that was required on the frontend to be done was to make a call to this endpoint with the necessary data. The entire process can be summarized as follows:
- The recently registered user clicks on the verification link she receives on her email
- The above step opens the link, which is of the format http://fossasia.github.io/open-event-frontend/verify?token=
- As soon as the frontend server receives this request, it extracts the token from the URL query parameter
- The token is now sent to the backend server as a patch request
- The response of the above request confirms whether the user verification is successful or not, and an appropriate message is displayed
In the frontend code, the above algorithm is spread across 3 files: the router, verify route and verify controller. A new route named /verify was implemented for the user verification, and was registered in the project’s main router.js file. After that, in the verify route, the beforeModel() method is used to trigger the above algorithm before the page is loaded:
// in app/routes/verify.js beforeModel(transition) { this.controllerFor('verify').verify(transition.queryParams.token); }
The main algorithm above is implemented in the verify controller:
// in app/controllers/verify.js ... queryParams : ['token'], token : null, success : false, error : null, verify(tokenVal) { let payload = { data: { token: tokenVal } }; return this.get('loader') .post('auth/verify-email', payload) .then(() => { this.set('success', true); }) .catch(reason => { this.set('error', reason); this.set('success', false); }); } });
A template for displaying the success or failure messages to the user was also created. It uses the value of the success boolean set above to decide the message to be displayed to the user. The user registration workflow is now complete and the user sees the following message after clicking on the verification link she receives:
You must be logged in to post a comment.