Skip to content

fix(auth): preserve safe login redirect path - #1522

Merged
khaira777 merged 4 commits into
mainfrom
fm/flocafe-customer-display-login-redirect
Nov 8, 2026
Merged

khaira777 merged 4 commits into
mainfrom
fm/flocafe-customer-display-login-redirect

Conversation

@khaira777

@khaira777 khaira777 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1514

Intent

also for customer diaplay in settings it shows: http://10.0.0.37:3001/customer-display/
but when i click on it, if i have to login etc and on login it does not keep path and goes back to pos?

What Changed

  • Added resolveSafeRedirect in AuthGuard and wired /auth/login to navigate to a validated internal ?redirect= path after authentication and tenant selection instead of always falling back to getLandingPage.
  • Updated /customer-display to redirect signed-in users without a selected tenant to /auth/login?select_tenant=true&redirect=/customer-display when no paired display token is present.
  • Added unit, deterministic UI, and Playwright E2E coverage for resolveSafeRedirect, /customer-display login and tenant-selection redirects, and fallback handling for unsafe redirect targets, and updated docs/architecture/frontend.md.

Risk Assessment

✅ Low: The change cleanly preserves and validates same-origin login and tenant-selection redirects from /customer-display with deterministic and E2E test coverage.

Testing

Ran the deterministic auth UI unit suite (npm run test:auth-ui-deterministic), built the backend and static desktop frontend (npm run build && npm run build:frontend), executed all 5 end-to-end tests in frontend/e2e/customer-display-pairing.spec.ts against an isolated server instance on ports 43101-43103, and drove 3 live Chromium scenarios on ports 43201-43203 with 4 screenshot artifacts captured in the evidence directory; all checks and scenarios passed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Opening an unpaired /customer-display/ without a staff session redirects to /auth/login?redirect=/customer-display and returns to /customer-display showing active orders after sign-in ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/02-customer-display-after-login.png
Opening an unpaired /customer-display/ as an authenticated staff member without a selected tenant redirects to /auth/login?select_tenant=true&redirect=/customer-display and returns to /customer-displa… ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/03-select-tenant-redirect-preserved.png
Adversarial redirect parameters on /auth/login?redirect=... (external URLs, protocol-relative URLs, backslash-prefixed paths, /auth/login, /setup) are rejected and fall back safely to /pos ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/04-unsafe-redirect-fallback-pos.png

Unauthenticated /customer-display/ redirected to /auth/login?redirect=/customer-display
Customer display board rendered at /customer-display/ immediately after signing in from the login redirect
Multi-tenant Select Business screen at /auth/login?select_tenant=true&redirect=/customer-display preserving the customer display redirect
Fallback to /pos when navigating to /auth/login with unsafe redirect query parameters

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/layout/AuthGuard.tsx:178 - In AuthGuard.tsx:178-186, the new ?redirect= preservation under else if (!currentTenant) is placed after if (isPublicPath) return; (AuthGuard.tsx:172), while both /customer-display and /auth/login are in PUBLIC_PATHS (AuthGuard.tsx:54-55). As a result, AuthGuard never executes this branch on /customer-display or /auth/login (and non-public routes like /pos do not carry ?redirect= in window.location.search). Meanwhile, CustomerDisplayPage (frontend/src/app/customer-display/page.tsx:768-772) only redirects when pairedToken === null && !authLoading && !user, even though frontend/src/app/customer-display/page.tsx:776 and frontend/src/app/customer-display/page.tsx:848 require both user and currentTenant. Concrete sequence: when an unpaired browser has a valid multi-tenant token in localStorage without a selected tenant (user !== null, currentTenant === null, authLoading === false) and opens /customer-display/, neither AuthGuard nor CustomerDisplayPage redirects to /auth/login?select_tenant=true&redirect=/customer-display, leaving /customer-display/ stuck on the loading screen at frontend/src/app/customer-display/page.tsx:848. Redirect from CustomerDisplayPage when pairedToken === null && !authLoading && (!user || !currentTenant) (using /auth/login?select_tenant=true&redirect=/customer-display when user is present) and remove the unreachable window.location.search ?redirect= lookup in AuthGuard.tsx:178-186 (updating tests/auth-ui-deterministic.test.ts:886-935 accordingly).
  • ⚠️ frontend/src/components/layout/AuthGuard.tsx:40 - resolveSafeRedirect (frontend/src/components/layout/AuthGuard.tsx:37-48, consumed at frontend/src/app/auth/login/page.tsx:156) only checks trimmed.startsWith('//') || trimmed.startsWith('/\\') after .trim(), without rejecting embedded ASCII control characters (\t, \r, \n) or backslashes. For a concrete input such as raw = '/\t/evil.com' or '/\n\\evil.com', trimmed.startsWith('//') and trimmed.startsWith('/\\') are both false, so resolveSafeRedirect returns '/\t/evil.com'; the WHATWG URL parser strips ASCII tab/CR/LF before parsing, resolving '/\t/evil.com' against the current origin to http://evil.com/. Reject control characters and backslashes (and verify same-origin pathname resolution via new URL(trimmed, 'http://localhost')) in resolveSafeRedirect.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Opening an unpaired /customer-display/ without a staff session redirects to /auth/login?redirect=/customer-display and returns to /customer-display showing active orders after sign-in ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/02-customer-display-after-login.png
Opening an unpaired /customer-display/ as an authenticated staff member without a selected tenant redirects to /auth/login?select_tenant=true&redirect=/customer-display and returns to /customer-displa… ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/03-select-tenant-redirect-preserved.png
Adversarial redirect parameters on /auth/login?redirect=... (external URLs, protocol-relative URLs, backslash-prefixed paths, /auth/login, /setup) are rejected and fall back safely to /pos ✅ pass live ~/.no-mistakes/evidence/01M6YDYWXJ8HDP2ZEPNWZN90B4/04-unsafe-redirect-fallback-pos.png
  • npm run test:auth-ui-deterministic
  • npm run build && npm run build:frontend
  • cd 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/customer-display-pairing.spec.ts --config=playwright.config.ts --project=chromium --retries=0
  • Live Chromium Playwright run against isolated tests/e2e-server.cjs on ports 43201-43203 capturing screenshots for unauthenticated /customer-display/ login redirect, select_tenant=true&redirect=/customer-display tenant selection redirect, and unsafe ?redirect= fallback to /pos
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Honor safe internal ?redirect= targets after login and tenant selection so signing in from /customer-display returns to /customer-display instead of falling back to /pos.

Fixes #1514
@qodo-code-review

Copy link
Copy Markdown

ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing

@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve safe customer-display redirects after login

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Return staff to the customer display after login or tenant selection instead of the POS.
• Reject unsafe login redirect targets and retain the permission-based landing-page fallback.
• Add deterministic and end-to-end coverage, and document the redirect behavior.
Diagram

graph TD
  A["Display route"] --> B{"Paired token?"} -->|No| D{"Session ready?"} -->|No| E["Login or tenant"] --> F{"Redirect safe?"} -->|Yes| G["Display board"]
  B -->|Yes| C["Paired board"]
  D -->|Yes| G
  F -->|No| H["Tenant landing"]
Loading
High-Level Assessment

Keep the validated query-parameter approach: it preserves the destination across login and tenant selection without adding session-backed navigation state. The existing permission-based landing page remains the fallback for absent or unsafe targets.

Files changed (6) +375 / -10

Bug fix (3) +45 / -6
page.tsxHonor validated login redirect targets +5/-3

Honor validated login redirect targets

• Navigates to a safe internal redirect after both user and tenant are selected. Otherwise retains the tenant’s permission-based landing page.

frontend/src/app/auth/login/page.tsx

page.tsxPreserve the board destination during tenant selection +7/-3

Preserve the board destination during tenant selection

• Sends unpaired, signed-in users without a selected tenant to tenant selection with the customer-display return target. Unauthenticated users continue to receive a login redirect with that target.

frontend/src/app/customer-display/page.tsx

AuthGuard.tsxValidate internal post-login destinations +33/-0

Validate internal post-login destinations

• Adds resolveSafeRedirect to reject external, malformed, control-character, backslash, authentication, and setup destinations. Accepted paths are normalized before navigation.

frontend/src/components/layout/AuthGuard.tsx

Tests (2) +323 / -2
customer-display-pairing.spec.tsCover the customer-display login round trip +40/-2

Cover the customer-display login round trip

• Asserts that an unpaired display sends unauthenticated visitors to login with a return target, then shows the board after sign-in. Also checks that unsafe login redirect targets fall back to the POS.

frontend/e2e/customer-display-pairing.spec.ts

auth-ui-deterministic.test.tsTest redirect validation and auth navigation +283/-0

Test redirect validation and auth navigation

• Covers accepted and rejected redirect values, both customer-display login entry paths, and safe-target versus fallback navigation. Extends the UI test stubs needed to exercise these routes.

tests/auth-ui-deterministic.test.ts

Documentation (1) +7 / -2
frontend.mdDocument safe login redirects for customer displays +7/-2

Document safe login redirects for customer displays

• Explains how login redirect targets are validated and when the landing-page fallback applies. Documents the unpaired customer display’s login and tenant-selection routes.

docs/architecture/frontend.md

@khaira777 khaira777 changed the title fix(frontend): honor safe redirect parameter on login for customer display fix(auth): preserve safe login redirect path Nov 8, 2026
@qodo-code-review

qodo-code-review Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Login drops deep-link settings 🐞 Bug ≡ Correctness
Description
resolveSafeRedirect parses the requested destination but returns only its normalized pathname,
discarding the query string. When a user signs in through
/auth/login?redirect=%2Fsettings%3Ftab%3Dprinters, navigation reaches /settings without
tab=printers, so the settings page opens its default tab instead.
Code

frontend/src/components/layout/AuthGuard.tsx[67]

+  return normalized;
Relevance

●●● Strong

Clear correctness bug in the PR's own redirect feature; the stated intent is to return users to the
exact deep link. No rejection precedent found, and historical correctness findings in this area were
mostly accepted.

PR-#1435
PR-#1425

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new resolver uses parsed.pathname and returns normalized without parsed.search. Login
passes that result to router.push, while settings reads tab from the destination URL and
defaults to store when it is absent.

frontend/src/components/layout/AuthGuard.tsx[49-67]
frontend/src/app/auth/login/page.tsx[152-159]
frontend/src/app/(dashboard)/settings/page.tsx[418-425]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The safe-redirect resolver drops query parameters needed by destination pages, so login does not preserve query-driven deep links.

## Fix Focus Areas
- frontend/src/components/layout/AuthGuard.tsx[49-67]
- frontend/src/app/auth/login/page.tsx[152-159]

## Recommended Fix
After validating the URL's origin and pathname, return the normalized pathname together with its parsed search string and fragment. Add a test for a settings deep link with a `tab` parameter, while retaining the unsafe-redirect rejection tests.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #39
✅ Compliance rules (platform): 5 rules
✅ Cross-repo context — repo relationships
✅ REVIEW.md
Review mode: Auto: ⚖️ Balanced: Security-sensitive open-redirect validation across login and customer-display auth flows.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@khaira777
khaira777 merged commit f0c3c43 into main Nov 8, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-customer-display-login-redirect branch November 8, 2026 21:19
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.

fix(auth): preserve redirect query path on login for customer display

1 participant