hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
180 stars 105 forks source link

[FEAT]: Authentication - Basic Authentication #1

Closed buka4rill closed 2 months ago

buka4rill commented 3 months ago

Acceptance Criteria

User Registration [POST] /api/auth/register

  1. Registration Endpoint
  1. Unique Email
  1. Password Encryption

Request

POST /api/auth/register
{
  "firstName": String,
  "lastName": String,
  "email": String,
  "password": String,
  "confirmPassword": String
}

Successful Response

{
  "message": String,
  "user": {
    "id": String,
    "email": String,
  },
}

Error Response

{
  "message": String,
  "error": String,
  "statusCode": Int,
}

User Login [POST] /api/login

  1. email and Password Validation
  1. Token Generation
  1. Token Expiry

Request

POST /api/auth/login
{
  "email": String,
  "password": String,
}

Successful Response

{
  "accessToken": String,
  "expiresIn": Int,
}

Accessing Protected Routes

  1. Authorization Header
{
  "Authorization": "Bearer eyJhbGciOiJIUzI1N...."
}
  1. Role-based access control ?? (TBD: not sure if this is needed for boiler-plates)

Error Handling

  1. Invalid Credentials
{
  "message": "Invalid credentials",
  "statusCode": 401
}

Testing

  1. Unit Tests