👥👥

User Service

Stack

Golang
MySQL
JWT
Redis

Use Case

User Registration:
When a user registers, the User Service receives the user's name, email, and password.
The User Service generates a unique ID for the user.
It securely hashes the password and stores the user's ID, name, email, and hashed password in the MySQL database.
User Login:
When a user attempts to log in, the User Service receives the email and password.
It retrieves the user's record from the MySQL database based on the provided email.
The User Service verifies the provided password against the stored hashed password.
If the passwords match, the User Service generates a JWT containing the user's ID and signs it with a secret key.
The User Service returns the JWT to the user, allowing them to authenticate subsequent requests.
Authentication:
When the user makes subsequent requests to protected endpoints, they include the JWT in the request headers.
The User Service receives the request and verifies the authenticity of the JWT using the secret key.
It extracts the user's ID from the JWT and retrieves the corresponding user record from the MySQL database.
If the user is authenticated, the User Service allows the request to proceed; otherwise, it returns an error.

Data Structure

User:
ID (int)
Name (string)
Email (string)
Password (string)