Allow users to change their password #16

Open
opened 2026-10-07 20:21:42 +03:00 by ars9 · 0 comments
Owner

Summary

Once authentication is in place (depends on #15), users can only get a password through npm run user:create. Let a logged-in user change their own password from the UI.

Requirements

Server

  • New endpoint POST /api/v1/auth/password, available only to an authenticated user and only when auth is enabled.
  • Request body: { "oldPassword": "...", "newPassword": "..." } (validated DTO, both non-empty strings).
  • Checks oldPassword against the current user's stored hash and, if it matches, replaces the hash with a new scrypt hash of newPassword (same hashing as in user:create).
  • Responses:
    • 204 on success
    • 400 if the body is invalid or the old password doesn't match. Not 401: the client treats 401 as "not logged in" and redirects to the login page.
  • The current token stays valid after the change.
  • Documented in Swagger.

Client

  • New "Change password" page with two fields: old password, new password, repeat new password. No email confirmation, no 2FA.
  • Password fields have visibility toggle buttons.
  • Reachable from the same place as the logout action, and shown only when auth is enabled.
  • On success, show a confirmation message. On a wrong old password, show an error and keep the user on the page.
  • New strings in en.json; Storybook stories for any new client/src/ui/ components.

Docs

  • Mention the endpoint and the page in the relevant docs (docs/architecture.md).

Acceptance criteria

  • With the correct old password, the password changes: logging in works with the new password and fails with the old one.
  • With a wrong old password, the endpoint returns 400 and the stored hash is unchanged.
  • Unauthenticated requests return 401.
  • Server tests cover success, wrong old password, invalid body and unauthenticated access.
## Summary Once authentication is in place (depends on #15), users can only get a password through `npm run user:create`. Let a logged-in user change their own password from the UI. ## Requirements ### Server - New endpoint `POST /api/v1/auth/password`, available only to an authenticated user and only when auth is enabled. - Request body: `{ "oldPassword": "...", "newPassword": "..." }` (validated DTO, both non-empty strings). - Checks `oldPassword` against the current user's stored hash and, if it matches, replaces the hash with a new scrypt hash of `newPassword` (same hashing as in `user:create`). - Responses: - `204` on success - `400` if the body is invalid or the old password doesn't match. Not `401`: the client treats `401` as "not logged in" and redirects to the login page. - The current token stays valid after the change. - Documented in Swagger. ### Client - New "Change password" page with two fields: old password, new password, repeat new password. No email confirmation, no 2FA. - Password fields have visibility toggle buttons. - Reachable from the same place as the logout action, and shown only when auth is enabled. - On success, show a confirmation message. On a wrong old password, show an error and keep the user on the page. - New strings in `en.json`; Storybook stories for any new `client/src/ui/` components. ### Docs - Mention the endpoint and the page in the relevant docs (`docs/architecture.md`). ## Acceptance criteria - With the correct old password, the password changes: logging in works with the new password and fails with the old one. - With a wrong old password, the endpoint returns `400` and the stored hash is unchanged. - Unauthenticated requests return `401`. - Server tests cover success, wrong old password, invalid body and unauthenticated access.
ars9 added this to the User management milestone 2026-10-07 21:20:28 +03:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ars9/liqa#16