- How to send payload from frontend to backend.
- Generate a unique session ID.
- Store the unique session ID to the redis alongside user information and necessary information.
- suggested key is
session:${sessionId}
- suggested key is
- How verify that the payload is valid.
- Use the session ID in the authorization bearer that can be used to find in redis database and retrieve the neccessary information.
- How to save user information to redis.
- redis.set(
session:${sessionId}
, JSON.stringify(userData));
- How to perform open authentication.
- Use passport.js and its modules for specific authentication method.
- How does "remember me" works after being checked after submitting?
- By extending the expiration date of the session ID.
- How to perform reverse proxy and use load balancer.
- Reverse Proxy
- Used as intermediary between client and a web server.
- Can be used as a load balancer by redirecting request to the list of servers that is available.
- Load Balancer
- Express Gateway - An open source api gateway for express.js this can be used for microservices architectures.
- PM2 - A node package manager that has a load balancing features. Note: Load balancing is performed inside the machine.
Task:
- Received (Authorization bearer sessionID as a token)
- Reponse JSON
start with
- local register authentication
- access protected routes
- local login authentication
Thoughts:
-
SessionId generation
- There is no specified rule on how the id is generated as long as it is unique.
-
Redis
- Use ioredis-mock for testing redis on the local machine without creating a new connection(in memory).
- Primary methods being used is set and get.
- redis.set() requires a key and a value in string(if a json object is being used)
- redis.get() request a key only return null if the key is not found.