Skip to content

[BE-13] Implement forgot-password and password reset flow #738

Description

@mftee

Overview

Users who forget their password have no way to recover their account. There is no forgot-password or reset-password endpoint. The MailService is set up and UsersService.update() can write a new passwordHash, so only the controller logic and reset token mechanism are missing.

Background

Files relevant:

  • backend/src/auth/auth.controller.ts — add two endpoints:
    • POST /api/auth/forgot-password — accepts { email }, sends reset link
    • POST /api/auth/reset-password — accepts { token, newPassword }, updates hash
  • backend/src/auth/auth.service.ts — add forgotPassword() and resetPassword() methods
  • backend/src/mail/mail.service.ts — add sendPasswordReset(to, token) method

Token approach: signed JWT with 1-hour expiry containing the user's ID and a purpose: 'password-reset' claim. Store no server-side state — just verify the JWT signature and expiry on the reset endpoint.

Acceptance Criteria

  • POST /api/auth/forgot-password always returns 200 (do not reveal whether email exists)
  • Reset email is sent if the email matches a registered user
  • POST /api/auth/reset-password validates the token, hashes the new password, and updates the user
  • Expired or reused tokens return 400 Bad Request
  • Password is re-hashed with bcrypt (same saltRounds: 12 as registration)

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions