An application that uses a one-time password (OTP) to validate users' email addresses and phone numbers.
Demo
The application uses nodejs and MongoDB in the backend. When the user hits the /register
route with his/her email address/phone number
- The controller saves the user data in the database.
- Generates and saves the OTP with userId in the database.
- With help of regular expression, it checks whether the given input is an email address or a phone number and sends the OTP accordingly to it, after that sending back the response to the client.
- Client receives OTP, enters it, and hit the
/verify
route. If it is correct, the controller updates the database. If it is invalid, the controller will inform the client.
In the database, verified
field is updated to true
upon successful verification.
Note: email
field in the database is used interchangeably to store email and phone number.