Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Send OTP #458

Open
5 tasks
Nainah23 opened this issue Aug 5, 2024 · 0 comments
Open
5 tasks

[Feat]: Send OTP #458

Nainah23 opened this issue Aug 5, 2024 · 0 comments
Labels

Comments

@Nainah23
Copy link
Contributor

Nainah23 commented Aug 5, 2024

Description

Implement a feature to send an OTP to the user for the endpoint api/v1/auth/request/token. Before sending a new OTP, the system should check if an existing OTP for the user already exists. If an existing OTP is found, it should be deleted before a new OTP is generated and sent.

Acceptance Criteria

  • The endpoint must return a 422 error for missing or invalid input with an appropriate error message.
  • A 401 status code should be returned for invalid credentials with an appropriate error message.
  • A successful request should return a 200 response with a success message.
  • OTP should be transmitted securely to the user via email or SMS.
  • Once validation checks are passed, an OTP is generated for the user and sent as part of the response payload.

Expected Outcome

  • The user should receive the OTP successfully or receive an error message if unsuccessful.
  • Users are informed of OTP request activity.

Requirements

Corresponding database fields for:

  • Email Address
  • OTP Token
  • OTP Expiry Time

Send OTP [POST] /api/v1/auth/request/token

Request

POST /api/v1/auth/request/token
Content-Type: application/json

{
  "email": "[email protected]"
}

Successful Response

{
  "message": "OTP has been sent to your email."
}

Error Response

Missing or Invalid Input

{
  "message": "Invalid input.",
  "error": "Email is required.",
  "status_code": 422
}

Invalid Credentials

{
  "message": "User not found.",
  "error": "No user exists with the provided email.",
  "status_code": 401
}

Implementation Steps

  1. New Method in AuthService:

    • Create a new method requestOtp in authservice.ts that handles the logic for checking existing OTPs, deleting them if found, generating a new OTP, and sending it to the user.
  2. Modify OTP Service:

    • Update the OTP service to include a method for checking existing OTPs and deleting them.
  3. Update Routes:

    • Add a new route in the authentication routes file to handle requests to api/v1/auth/request/token.
  4. Unit Tests:

    • Write unit tests for the new method to ensure it behaves as expected, including scenarios where an existing OTP is found and deleted, and where no existing OTP is found.

Check List

  • Endpoint api/v1/auth/request/token created
  • Logic to check for existing OTP and delete if found
  • Logic to generate and send new OTP
  • Appropriate success and error responses
  • Unit tests for new functionality
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants