Repository navigation
feat(auth): add quick PIN sign-in and mode toggle - #1524
Conversation
|
ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoAdd quick PIN sign-in and compact mode toggles across POS, KDS, and Server App
AI Description
Diagram
High-Level Assessment
Files changed (12)
|
Code Review by Qodo
1. Staff can reuse a previous user's password
|
af9bc0a to
c8a4b53
Compare
…ite (Shard 4/4)` and `End-to-End Playwright Tests` (`Playwright E2E (Shard 2/4)` and the cascading timeouts in Shards 1 and 3): 1. **`Core Test Suite (Shard 4/4)` — `test:kds-broadcast-grouping` (`MODULE_NOT_FOUND: '@/lib/login-errors'`)** - **Invariant**: Modules imported by `frontend/src/hooks/useKdsConnection.ts` must resolve under both Next.js (`frontend/tsconfig.json`) and root `ts-node` (`tsconfig.json`, used by `tests/kds-broadcast-grouping.test.ts` without `@/*` path aliases). - **Fix**: Changed `import { parseLoginFailure } from '@/lib/login-errors'` to `'../lib/login-errors'` in `frontend/src/hooks/useKdsConnection.ts`. 2. **`End-to-End Playwright Tests` (`Playwright E2E` Shards 1, 2, 3) — PIN mode toggle & E2E PIN state cleanup** - **Invariants**: - Focusing or typing into the email/password fields on POS (`/auth/login`), KDS (`KdsLoginForm`), or Server App (`/server-standalone`) must lock `signInMode` to `'password'` so an asynchronous `GET /api/auth/pin-users` response never unmounts an active password form mid-interaction. - E2E helpers that log in with email/password while approval PINs are configured in the suite must switch to the password tab (`signin-mode-password`), and E2E suites that configure staff PINs must clear/deactivate those PINs in teardown so subsequent specs in the same shard start with `pinUsers = []`. - **Fixes**: - `frontend/src/app/auth/login/page.tsx`, `frontend/src/components/kds/KdsLoginForm.tsx`, and `frontend/src/app/server-standalone/page.tsx`: unified `signInMode` as `'pin' | 'password' | null` (defaulting to `'pin'` when `pinUsers.length > 0` and no email/password is entered), locked `signInMode` to `'password'` on email/password `onFocus`, and cleared email/password when switching back to `signin-mode-pin`. - `frontend/e2e/ops-admin/helpers.ts` and `frontend/e2e/approval-manager-selection.spec.ts`: awaited `/api/auth/pin-users` on `/auth/login` and clicked `signin-mode-password` when visible before filling `#email` and `#password`. - `frontend/e2e/pin-quick-switch.spec.ts`, `frontend/e2e/approval-manager-selection.spec.ts`, and `frontend/e2e/i18n-batch-5d.spec.ts`: cleared temporary staff PINs (`pin: null`) and deactivated disposable PIN staff (`POST /api/staff/:id/deactivate`) using fresh owner tokens in teardown. 3. **Verification**: - `npm run test:kds-broadcast-grouping` (passed) - `npx ts-node --transpile-only tests/pin-quick-switch.test.ts` (passed) - `npx ts-node --transpile-only tests/auth-ui-deterministic.test.ts` (passed) - `npm run lint && npm run build && npm run build:frontend && npm run docs:check && git diff --check` (passed) - Playwright E2E (`e2e/approval-manager-selection.spec.ts`, `e2e/auth.spec.ts`, `e2e/ops-admin/dashboard-reconciliation.spec.ts`, `e2e/ops-admin/orders-lifecycle.spec.ts`, `e2e/pin-quick-switch.spec.ts` — 19/19 passed)
3616756 to
5d7a86d
Compare
Fixes #1516
Intent
can we also add quick sign in on the kds screen as well simialr to main pos? do the same for server app too, also the quick sign in and normal sign in , make a toggle somewhere so its not long vertically and is easy to use?
What Changed
GET /api/auth/pin-usersandPOST /api/auth/pin-loginon the standalone KDS (:3002) and Server App (:3003) servers, plus?scope=kdsfiltering on:3001, enforcingkitchen.usewith active station checks on KDS andserver-app.useon Server App along with per-user PIN verification locks and IP+user rate-limit lockouts./auth/login), KDS (KdsLoginForm,useKdsConnection,/kds-standalone), and Server App (/server-standalone).tests/pin-quick-switch.test.tsandfrontend/e2e/pin-quick-switch.spec.ts.Risk Assessment
✅ Low: The PIN quick sign-in endpoints, permission/station filtering, and segmented mode toggles across POS, KDS, and Server App are well-bounded, consistent with existing authentication and rate-limiting contracts, and all prior review findings are resolved.
Testing
Ran
npm run test:pin-quick-switch, built the backend and static frontend (npm run build && npm run build:frontend), executed the Playwright E2E suitefrontend/e2e/pin-quick-switch.spec.tsagainst isolated Main POS, KDS, and Server App servers, and drove an interactive Chromium session capturing 10 screenshots covering the Quick Switch / Password mode toggle, role-filtered user tile pickers, wrong-PIN error handling, and authenticated workspaces across all three surfaces.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
frontend/src/components/kds/KdsLoginForm.tsx:51- InKdsLoginForm.tsx,handlePinLoginfailures are stored inconn.loginError(frontend/src/hooks/useKdsConnection.ts:787), while the localpinErrorstate (frontend/src/components/kds/KdsLoginForm.tsx:21) is never set to a non-empty string anddisplayPinErrorreadspinError || conn.loginError(KdsLoginForm.tsx:51). As a result, allsetPinError('')calls inKdsLoginForm.tsx(lines 26, 31, 36, 43, 76, 94, 135, 178, 251) are no-ops: after a failed PIN attempt,conn.loginErrorremains visible when typing a new PIN, cancelling (pin-login-cancel), selecting a different staff tile, or switching to the Email/Password tab (signin-mode-password), and a failed Email/Password attempt likewise leaksconn.loginErrorinto the PIN form when switching tosignin-mode-pin. In addition, switching tosignin-mode-passwordinfrontend/src/components/kds/KdsLoginForm.tsx:92-95andfrontend/src/app/server-standalone/page.tsx:1339-1342does not resetselectedPinUserorpin(unlikefrontend/src/app/auth/login/page.tsx:338-340), leaving a partially typed PIN and selected user active when toggling back to PIN mode.frontend/src/components/kds/KdsLoginForm.tsx:27-KdsLoginForm.tsx(lines 27, 165, 172, 179) andserver-standalone/page.tsx(lines 831, 1412, 1419, 1426) display{pin.length}/8and allow entering up to 8 digits on the PIN keypad and input (maxLength={8},prev.length < 8,.slice(0, 8)). However, staff PINs in FloCafe are strictly 4-6 digits (main/routes/staff.ts:92andfrontend/src/app/auth/login/page.tsx:390,396,411,436), and all three backend PIN login handlers (main/kds-server.ts:478,main/server-app.ts:474,main/routes/auth.ts:475) reject any PIN not matching/^\d{4,6}$/with HTTP 401 (invalid_pin_format) while incrementingincrementFailedLogin(pinRateKey)toward lockout. Cap the PIN input, keypad, and counter at 6 digits in both components to match the backend contract and main POS login.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:pin-quick-switchnpm run test:rtl-setup-auth-settingsnpm run test:rtl-kds-server-whatsappnpm run test:auth-ui-deterministiccd frontend && CI=1 E2E_BASE_URL=http://127.0.0.1:43101 E2E_KDS_BASE_URL=http://127.0.0.1:43102 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:43103 npx playwright test e2e/pin-quick-switch.spec.ts --config=playwright.config.ts --project=chromium✅ No issues found.
npm run test:pin-quick-switchnpm run build && npm run build:frontendcd frontend && CI=1 E2E_BASE_URL=http://127.0.0.1:43001 E2E_KDS_BASE_URL=http://127.0.0.1:43002 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:43003 npx playwright test e2e/pin-quick-switch.spec.ts --config=playwright.config.ts --project=chromium --retries=0Live Playwright Chromium verification against isolatedtests/e2e-server.cjsinstances on ports 44001-44003 capturing 10 screenshots across Main POS, KDS, and Server App✅ **Document** - passed
✅ No issues found.
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.