Feature : Create a Login and Logout API based on OAuth
fallen-ecstasy opened this issue · 1 comments
fallen-ecstasy commented
Create Login API
- Create an API for Login the User.
Request Format
{
email: String,
pass: String
}
Response Format
{
message : String,
token_type: "Bearer",
token : String
}
-
Name the Router
authRouter
-
Create this
authRoutes.ts
in the./src/Routes/
Folder, If the folder is not present create it yourself. -
Create an Interface for the Request and Response to ensure type-checking.
-
Use
validator
to Validate the Email and Password Criteria. -
Response should have an appropriate message.
-
Handle all Errors and Edge cases for the Given API.
OAuth Task
- After Successful Login, Generate a Token and Store it in Redis Cache.
- Token Should be created using
jsonwebtoken
and will be based onsessionCount + email
of the user. - Create 2 Entries for the session,
token -> userId
anduserId -> token
. - Set Token Expiration to
86400s
i.e. 24 Hours. - Ensure not having Redundant Entries.
- If Session Exists, Return the Session Id, else Create the session.
Create Logout API
Request Format
header:{
...
Authorization : "Bearer SOME_TOKEN"
}
Response Format
{
message : String,
}
OAuth Task
- To log out of the User, Check token validity.
- If the Token is Valid, Delete the Token from Redis Cache, along with UserId.
- Response with Appropriate message.
Testing
- Write a Test in Mocha + Chai to test the Login and Logout API through Redis entries.
Zenith-17 commented
Hi, I am interested in working on this issue, Kindly assign it to me.