Developing an API for mobile clients on Laravel . I use Laravel Passport as a user authentication and issue a Personal Access token when I log in to the system.
I can not figure out how to implement an email confirmation system (mobile phone - it does not matter) when registering a user. It is necessary that the confirmation takes place using a четырёхзначного числа - the code.
Traditionally, sites send a letter with an activation code after sending the registration form and only after that activate the account. As far as I understand, in this case the user record in the database will already exist. Accordingly, until the user confirms it, it is theoretically possible that another person will come during this time and will want to create an account with the same mailbox. And here in the database there are 2 non-activated records. Sooner or later, one of the users activates the account, then what to do with the second? Of course, I understand that the activation code is temporary, but it does not solve this problem.
I do not like this approach. I wanted the user record to be created only after he confirmed the password and registered. How, then, to arrange the logic on the server and communicate with the client?
I roughly thought of the following:
- User enters your email
- Mobile client sends custom email to API
- The API creates an entry in a separate table, where there is a correspondence email - code
- The API sends an email with a code to the mail
- The user enters the code in the email confirmation field and fills in the other fields of the registration form.
- The mobile client sends all user data to the API along with the code.
- The API in a separate table (users) creates a user account.
How safe is this approach and what are the disadvantages? What do you advise?