fallen-ecstasy/NovaCode-Server

Feature : Create a Login and Logout API based on OAuth

Opened this issue · 1 comments

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 on sessionCount + email of the user.
  • Create 2 Entries for the session, token -> userId and userId -> 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.

Hi, I am interested in working on this issue, Kindly assign it to me.