Repository navigation
feat(auth): self-service PIN/password & reset - #1540
Conversation
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
@greptile review |
[Critical impact] Credential changes reach signed-in access across all three app interfaces and staff accounts. Fix the credential-write races and session mix-ups before merging. Findings
|
…ntials.reset Allow every active user across all roles (owner, manager, cashier, server, chef) and surfaces (:3001 Main API, :3002 Standalone KDS, :3003 Standalone Server App) to change their own password and set or rotate their own 4-6 digit PIN after verifying their current credential, returning a fresh session JWT while invalidating prior tokens. Gate admin credential overrides on PUT /api/staff/:id behind a new configurable Owner-default permission (staff.credentials.reset) alongside canModifyTargetStaff so Owners can reset any account by default and Managers can reset operational staff credentials only when explicitly granted.
…to-End Playwright Tests & Playwright E2E Shards (1/4 - 4/4): - Invariant: Test discovery across all environments must be cross-platform and must never make unconditional top-level filesystem writes to hardcoded developer-local paths. - Root Cause: `frontend/e2e/self-service-credentials-live.spec.ts` executed top-level `fs.mkdirSync('/Users/gurkiratkhaira/...')` on import. In Ubuntu CI runners, `/Users` does not exist and unprivileged runners cannot create it (`EACCES: permission denied, mkdir '/Users'`), crashing Playwright test discovery across all shards. - Fix: Updated `EVIDENCE_DIR` in `frontend/e2e/self-service-credentials-live.spec.ts` to check `fs.existsSync(path.dirname(DEFAULT_LOCAL_EVIDENCE))` and fall back to `path.join(os.tmpdir(), 'no-mistakes-evidence', ...)` if the local path is inaccessible. 2. Lint & Build Validation (Linux): - Invariant: All committed code must adhere to repo-pinned formatting rules checked by `check-changed-format.cjs`. - Root Cause: `frontend/e2e/self-service-credentials-live.spec.ts` had unformatted formatting variances. - Fix: Formatted the file using `oxfmt`, verifying that both `scripts/ci/check-changed-format.cjs` and `npm run lint` succeed with 0 errors. 3. Core Test Suite (Shard 2/4 - `test:cash-sessions`): - Invariant: Test fixtures setting up isolated day-level shifts and Z-reports for a specific business date must clean up all preexisting drawer movements on that business date to prevent cross-section test pollution. - Root Cause: In `tests/cash-sessions.test.ts`, earlier test sections dynamically used the current execution date (`2026-11-10`), creating drawer movements (2700c total). Section 11's pre-test cleanup only deleted movements where `movement_type = 'opening_float'`, leaving non-float pay-in movements in the DB and causing unscoped X and day Z report assertions to fail with 10700c instead of 8000c. - Fix: Updated the cleanup query in Section 11 to `DELETE FROM cash_drawer_movements WHERE business_date = '2026-11-10'`, cleanly clearing all drawer movements for that date before shift execution. Local Verification: - `node scripts/ci/check-changed-format.cjs --base 400492f` (Passed: 0 errors) - `npm run lint` (Passed: 0 backend errors, 0 frontend errors) - `npm run lint:budget` (Passed: backend 991/1000, frontend 0/5) - `npm run build` (Passed) - `npm run build:frontend` (Passed) - `npm run test:self-service-credentials` (Passed: 100% assertions green) - `npm run test:cash-sessions` (Passed: 366/366 passed) - `env SHARD_TOTAL=4 SHARD_INDEX=1 node scripts/ci/run-test-shard.cjs` (Passed: 59/59 suites in Shard 2/4 passed) - `cd frontend && npx playwright test --list` (Passed: 434 tests discovered without permission errors)
… Build Validation (Linux):** - **Cause:** `tests/cash-sessions.test.ts` had a single unformatted line violating `oxfmt` standards checked by `scripts/ci/check-changed-format.cjs`. 2. **Playwright E2E (Shard 2/4):** - **Cause:** `frontend/e2e/layout-integrity.spec.ts` tested Escape key behavior for the "Reset PW" modal while logged in as `manager`. Because `staff.credentials.reset` defaults to `owner` only, the "Reset PW" button was not visible to `manager`. 3. **Playwright E2E (Shard 3/4):** - **RTL POS:** `frontend/src/app/(dashboard)/staff/page.tsx` used dynamic localized `aria-label={tAuth('togglePinVisibility')}`. In RTL/Persian mode, this broke `locator('button[aria-label="Toggle PIN visibility"]')` in `rtl-dashboard-pos-common.spec.ts`. - **Server App Header:** `frontend/e2e/server-app-ordering.spec.ts` asserted `toHaveCount(2)` on header buttons. The self-service credentials button added a third button. - **State Leakage across Shard 3:** `self-service-credentials-live.spec.ts` created staff users with PINs without clearing them on teardown. When any staff has a PIN, the POS/Server App switch to PIN quick-switch mode, detaching `#email` and breaking subsequent tests. --- ### Applied Fixes - [`tests/cash-sessions.test.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/tests/cash-sessions.test.ts#L2421): Formatted via `oxfmt`. - [`frontend/e2e/layout-integrity.spec.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/frontend/e2e/layout-integrity.spec.ts#L559): Added `loginAsOwner` helper with `/api/auth/pin-users` sync and updated staff modal tests to authenticate as `owner`. - [`frontend/src/app/(dashboard)/staff/page.tsx`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/frontend/src/app/(dashboard)/staff/page.tsx#L458-L665): Restored canonical static `aria-label="Toggle PIN visibility"` and `aria-label="Toggle password visibility"`. - [`frontend/e2e/server-app-ordering.spec.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/frontend/e2e/server-app-ordering.spec.ts#L173-L188): Updated header button count expectation to 3, included credentials button in touch target size assertions (>= 44x44px), and added auto-lock setting sync. - [`frontend/e2e/self-service-credentials-live.spec.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/frontend/e2e/self-service-credentials-live.spec.ts#L50-L105): Added `test.afterAll` hook to clear PINs, deactivate created test staff, restore manager role overrides, and prevent database pollution. --- ### Verification Summary - `node scripts/ci/check-changed-format.cjs --base 400492f`: Passed (0 errors). - `npm run lint` & `npm run lint:budget`: Passed (0 errors). - `npm run build` & `npm run build:frontend`: Passed (clean compilation and export). - `npm run test:self-service-credentials`: Passed. - Playwright E2E suites: `layout-integrity.spec.ts`, `rtl-dashboard-pos-common.spec.ts`, `self-service-credentials-live.spec.ts`, `server-app-ordering.spec.ts`, `settings-e2e-read-budget.spec.ts`, and `settings-kds-navigation.spec.ts` all passed cleanly
…Build Validation (Linux)` & `ci-2`, `Required Checks Gate`):** - **Invariant violated:** All changed frontend and backend files against the pull request base must strictly adhere to the repository formatting specification enforced by `oxfmt` via `scripts/ci/check-changed-format.cjs`. - **Scope & sibling locations:** In the pull request change set (58 changed files total; 13 changed frontend files and 9 root files), `frontend/e2e/server-app-ordering.spec.ts` had a multiline arrow function format deviation introduced in the prior round. All other changed frontend and root files were checked and verified clean against the base commit. ### Root Cause In `frontend/e2e/server-app-ordering.spec.ts`, the `page.waitForResponse` callback around line 827 was formatted across multiple lines in a way that violated `oxfmt` rules, causing `node scripts/ci/check-changed-format.cjs` to exit with code 1 during the `Lint & Build Validation (Linux)` workflow job. This in turn blocked the downstream `Required Checks Gate`. ### Applied Fix - Formatted [`frontend/e2e/server-app-ordering.spec.ts`](file:///Users/gurkiratkhaira/.no-mistakes/worktrees/de2296f2e6f8/01M71NAA3AJKJCX81VZ1YA2HZ7/frontend/e2e/server-app-ordering.spec.ts#L827-L829) with `oxfmt` to collapse the single-expression callback into canonical single-line form: ```ts const autoLockSettingLoaded = page.waitForResponse((res) => res.url().includes('/api/settings/auto_lock_minutes'), ); ``` ### Local Verification 1. `node scripts/ci/check-changed-format.cjs --base 400492f` - Passed (0 format issues across 58 changed files). 2. `npm run lint` - Passed (991 backend warnings, 0 errors; 0 frontend warnings, 0 errors). 3. `npm run lint:budget` - Passed (backend 991/1000, frontend 0/5). 4. `npm run build` - Passed (TypeScript backend clean compilation to `dist/`). 5. `npm run build:frontend` - Passed (Next.js desktop static export clean build). 6. `npm run test:script-coverage` - Passed (279 reachable scripts, 340 test files covered). 7. `npm run test:self-service-credentials` - Passed (100% assertions green). 8. `git diff --check` and `git status --short` - Clean, touching only the formatted lines in `frontend/e2e/server-app-ordering.spec.ts`
…rotation expiry, and session updates
2de3c74 to
6e49184
Compare
Intent
Every user regardless of role (
owner,manager,cashier,waiter,chef) must be able to change their own PIN and their own password after entering their current one. For resetting other users' passwords or PINs without entering their current one (so forgotten credentials can be reset): by default only Owners are allowed to reset passwords/PINs without the current one, and Managers are allowed to reset operational staff passwords/PINs without the current one only when explicit permission is granted to them.What Changed
POST /api/auth/password/changeandPOST /api/auth/pin/changeendpoints across the main API, KDS, and Server App with rate limiting, current-credential verification, and token rotation, surfaced via a newAccountCredentialsDialogaccessible across dashboard, KDS, and Server App interfaces.staff.credentials.resetpermission (granted to Owners by default) that gates resetting passwords or PINs onPUT /api/staff/:id, allowing Owners to reset any user's credentials and Managers to reset operational staff credentials only when explicitly permitted.staff.credentials.reset, added PIN clearing support, and reissued active session tokens when an administrator updates their own credentials.Risk Assessment
✅ Low: The self-service and administrative credential reset workflows are rigorously bounded across all five roles and all three server listeners with complete permission enforcement, session invalidation, and rate limiting.
Testing
Stood up the live isolated FloCafe backend and static frontend across all three server instances (:3101 Main POS, :3102 Standalone KDS, and :3103 Standalone Server App) and drove 6 live end-to-end user scenarios in Chromium; all 6 scenarios passed, capturing 13 reviewer-visible screenshots covering self-service password changes, PIN setups and rotations, adversarial rate-limit lockouts, KDS and Server App dialogs, and Owner versus Manager staff credential resets.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
frontend/e2e/self-service-credentials-live.spec.ts- new test file written by agent: frontend/e2e/self-service-credentials-live.spec.tsnpm run test:self-service-credentialsnpm run test:script-coveragenpx playwright test e2e/self-service-credentials-live.spec.ts --project=chromium✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.