Skip to content

Let users change their own password in the gateway - #323

Open
abeldantas wants to merge 4 commits into
mainfrom
feat/gateway-self-service-password
Open

Let users change their own password in the gateway#323
abeldantas wants to merge 4 commits into
mainfrom
feat/gateway-self-service-password

Conversation

@abeldantas

@abeldantas abeldantas commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a PUT /auth/me/password endpoint that lets authenticated users change their own password by providing current + new password.
  • Adds a "Change password" dialog in the gateway NavRail so users can change their password from the UI.
  • Validates new password length (min 8 chars) and verifies the current password before updating.
  • OIDC-provisioned users (no local password hash) get a clean 403, not a crash.
  • Existing JWTs remain valid after a password change — acceptable for v1, since tokens are short-lived and there is no revocation list yet.
  • Includes endpoint tests covering success, wrong current password, too-short password, and the OIDC no-hash case.

Test plan

  • pytest tests/switch_core/gateway/test_change_password.py — 5 tests pass.

A dashboard user who knows their current password can now set a new one
without involving an admin.  This is the first slice of f17 (self-service
password management); admin-initiated resets are out of scope here.

Backend: PUT /auth/me/password — verifies the current password, hashes
the replacement, and commits.  Rejects OIDC-only accounts (no hash to
verify against) with 403.

Frontend: ChangePasswordDialog accessible from the NavRail account menu,
following the existing CreateUserDialog pattern (MUI Dialog, inline
error/success alerts, confirm-password guard).
The change-password endpoint accepted any string, including empty — a
curl call could set an account's password to "" and leave it
unrecoverable from the login form.  Add min_length=8 on
ChangePasswordRequest.new_password so Pydantic rejects degenerate
values before the handler runs.

Also adds the missing test coverage: happy path, wrong current
password → 403, short password → 422, empty password → 422.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds self-service password change support to the Switch Gateway, wiring a new authenticated backend route through the frontend UI and covering the behavior with unit tests.

Changes:

  • Adds a Gateway UI “Change password” dialog and a NavRail menu entry to open it.
  • Introduces a frontend API helper to call the password change endpoint.
  • Implements PUT /auth/me/password in the gateway backend with a request schema and tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gateway/src/layout/NavRail.tsx Adds a “Change password” menu item and mounts the dialog.
gateway/src/layout/ChangePasswordDialog.tsx New dialog UI for submitting current/new password and surfacing success/error.
gateway/src/data/api.ts Adds changePassword() client wrapper calling the backend route.
core/tests/switch_core/gateway/test_change_password.py Adds route-level tests for success and validation/error cases.
core/switch_core/gateway/schemas.py Adds ChangePasswordRequest schema with min-length validation.
core/switch_core/gateway/auth_routes.py Implements PUT /auth/me/password and updates the user password hash.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gateway/src/layout/ChangePasswordDialog.tsx Outdated
Comment thread core/switch_core/gateway/auth_routes.py
Guard handleClose so it's a no-op during an in-flight request,
preventing stale success/error state on next open.
Add autoComplete attributes (current-password / new-password) to the
TextFields so password managers integrate correctly. Add a test for the
OIDC user case (password_hash=None → clean 403).
@abeldantas abeldantas changed the title feat(gateway): let logged-in users change their own password Let users change their own password in the gateway Aug 31, 2026

@amaudruz amaudruz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Tried locally, changed the pw once, it worked, then tried to change a second time and got the error in the screenshot

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants