Today, we will understand how to create a complete logic flow for authorization and authentication of any type of application.
First of all, let’s considerate all the steps envolved in this process, they are:
- Database
- External integrations
- User origin check
- Signin
- Validations
- Treath of erros
- Sending confirmations
- Creating Password
- Login
- Session
- Password Reset
- Oportunities
So, now let’s get straight to the point, starting by the Database.
Database
The main objective of registrations are get data, it involve created it, read it, update it and when necessary delete it, and for became this processes viable, easy and trustlly we need create a database correctly.
In summary, a good database must be designed to avoid data inconsistency. In relational databases as which we will talk here, points to be observed are:
- Thinking about all tables that you will need to use.
- Define all constrains to avoid inconsistency in data
Here is a template to our database:
+------------------+ +--------------------+
| Users | | Orders |
+------------------+ +--------------------+
| id (PK) |<------->| id (PK) |
| name | | user_id (FK) |
| email | | product_id (FK) |
| created_at | | order_date |
+------------------+ +--------------------+
+------------------+ +--------------------+
| Products | | OrderDetails |
+------------------+ +--------------------+
| id (PK) |<------->| order_id (FK) |
| name | | product_id (FK) |
| price | | quantity |
| stock | | total_price |
+------------------+ +--------------------+