Skip to content

Implement Forgot Password (Use Existing Mail & OTP Logic) #187

@ahmadogo

Description

@ahmadogo

Description:

Implement a forgot‑password flow that uses the existing Mail Service (sendOtpEmail) to send a one‑time 6‑digit OTP to the user’s registered email, then verify OTP and reset the password securely.

Tasks:

  • Add DTOs: ForgotPasswordDto { email }, VerifyOtpDto { email; otp }, ResetPasswordDto { email; otp; newPassword }.
    In auth.service.ts:

    • forgotPassword(dto: ForgotPasswordDto) → call mailService.sendOtpEmail(dto.email).
    • verifyOtp(dto: VerifyOtpDto) → validate OTP via repository/cache, no secrets leaked.
    • resetPassword(dto: ResetPasswordDto) → verify OTP, hash new password, save, invalidate OTP.
  • Create/Use OTP repository/cache utilities already employed by sendOtpEmail (shared source of truth).

  • Enforce OTP 10‑minute expiry and one‑time use.

  • Add unit tests for: OTP request (delegates to mail), verify (ok/invalid/expired), reset (hash + invalidate).

  • Update Swagger (if present): request/response schemas and error codes.

Acceptance Criteria:

  • Calling forgotPassword triggers mailService.sendOtpEmail and sends an OTP to the user’s email.
  • OTP must be valid and unexpired to reset password.
  • Invalid or expired OTP returns 400/401 without revealing whether the email exists.
  • New password is securely hashed and persists; OTP is invalidated after use.
  • A screenshot of your server running

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions