Skip to content

Fixes #28295: keep the deep link a signed-out user opened through login - #38545

Merged
sweta1308 merged 4 commits into
mainfrom
fix-28295-deep-link-lost-on-login
Nov 24, 2026
Merged

sweta1308 merged 4 commits into
mainfrom
fix-28295-deep-link-lost-on-login

Conversation

@sweta1308

@sweta1308 sweta1308 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #28295

When a signed-out user opens a link to an entity, signing in sometimes sends them to the home page instead of that entity. The page to return to is saved in the redirectUrlPath cookie. On a cold load with no stored token, the cookie was sometimes never written.

Cause. resumeSignedInSession read the current location only after await getOidcToken(). With no token, initializeAuthState clears isAuthenticating first. The router then mounts, and UnAuthenticatedAppRouter redirects the protected URL to /signin while that await is still pending. When it returns, the location read is /signin. That is not a protected route, so nothing is stored, and after login PermissionProvider has no path to send the user to.

Fix. Capture the location before the await and pass it to handleStoreProtectedRedirectPath. That function now takes an optional location and defaults to the current one. Its other caller (authCoordinator.install's onRefreshStart, called with no arguments) is unchanged.

This code runs before the configured provider matters, so the fix applies to every provider: Keycloak and other OIDC, SAML, Basic, LDAP.

Type of change:

  • Bug fix

High-level design:

N/A — small change (2 files).

Tests:

Use cases covered

  • A signed-out user opens a protected entity URL, is redirected to /signin, signs in, and returns to that URL with its query string.
  • A plain sign-in from / still lands on /.
  • The existing callers (refresh-cycle onRefreshStart, refresh failure) still store the current location.

Unit tests

  • I added unit tests for the new/changed logic.
  • src/components/Auth/AuthProviders/AuthProvider.test.tsx: new test, "stores the deep link an unauthenticated user opened even after the router has moved to /signin". It holds getOidcToken pending, moves the router to /signin, then resolves with no token, and asserts that the original path and query string are stored.
  • The test fails with the old handleStoreProtectedRedirectPath() call and passes with the fix.
  • yarn test src/components/Auth/AuthProviders/AuthProvider.test.tsx: 50 passed, 0 failed.
  • Coverage on AuthProvider.tsx: 80.99% lines (whole file). All changed lines are covered.

Backend integration tests

  • Not applicable (no backend changes).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not run. make playwright_affected selects broad permissions/smoke specs because AuthProvider.tsx is shared. Locally, Auth/Login.spec.ts stops in auth.setup.ts with HTTP 404 /api/v1/ingestionRunners: my local backend doesn't serve that endpoint, which is unrelated to this change. The impacted specs are pending for the merge queue.
  • No new spec added. The bug is a timing race that main passes about 70% of the time, so an E2E spec could not reliably catch a regression. The deterministic regression test is the unit test above.

Manual testing performed

Local stack: backend on :8585 (Basic auth, sample data), UI via yarn start on :3000. A Playwright script opens /table/sample_data.ecommerce_db.shopify.agent_performance_summary/schema in a fresh, signed-out browser context. It records the redirectUrlPath cookie on /signin, signs in as admin through the form, and checks the final URL.

Code Runs Cookie missing on /signin Landed on / instead of the table
main 25 7 7
This PR 25 0 0

Every failure on main was the missing cookie followed by / after login, which is the reported symptom. A plain login from / still lands on / (3/3).

Verified evidence

1. Regression test: fails on main, passes with the fix (same test file, same command)

$ npx jest src/components/Auth/AuthProviders/AuthProvider.test.tsx -t "deep link an unauthenticated"

=== main @ 0b4291263aa (no fix) ===
    ✕ stores the deep link an unauthenticated user opened even after the router has moved to /signin
    Expected: "redirectUrlPath", "/table/sample.ecommerce.shopify.orders?tab=schema", Anything
    Number of calls: 0
Tests:       1 failed, 49 skipped, 50 total

=== this PR @ 3f5d0359c7c ===
    ✓ stores the deep link an unauthenticated user opened even after the router has moved to /signin
Tests:       49 skipped, 1 passed, 50 total

The test forces the race: the token lookup is still pending while the router moves to /signin. On main the cookie is never written (Number of calls: 0).

2. Real browser, this PR (3f5d0359c7c, local stack with sample data)

Signed out, opened the table URL, redirected to /signin, and the deep link is in the redirectUrlPath cookie:

After signing in as admin, the browser lands on the table itself, not the home page:

3. Repeated browser runs: see the table above. main lost the deep link in 7 of 25 runs; this PR in 0 of 25.

UI screen recording:

Not applicable — standalone bug fix with no visual change. Browser evidence is in the table above.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas. (No new comments: the change is two lines; the reasoning is here and in the commit message.)
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (N/A — no schema change.)
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). (N/A — bug fix, explained above.)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    Reviewed 31d0eb33a89. No 🔴. Fixed one 🟡: the new test's mock restore now runs in finally. 3f5d0359c7c after it only replaces the test's as any cast with jest.requireMock<jest.Mock>.
  • Decision check: N/A — no new contract, default, limit or ordering.
  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

resumeSignedInSession read the location only after awaiting getOidcToken.
With no stored token, initializeAuthState clears isAuthenticating first, so
the router can redirect the protected URL to /signin before that await
returns; the location then read is /signin, nothing is stored, and the user
lands on / after login. Capture the location before the await.
@sweta1308
sweta1308 requested a review from a team as a code owner November 24, 2026 05:48
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

UI browser tests

Ran: all test files (no impact map from main yet)

Result: ✅ 1070 passed · 154 skipped

Changed code executed by these browser tests: 0 / 5 lines (0%)

File Changed lines Executed %
src/components/Auth/AuthProviders/AuthProvider.tsx 5 0 0%

@gitar-bot

gitar-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Capturing the protected route before token lookup changes login redirection; a stale captured location could return users to an unintended in-app page.

Captures the protected deep link before resumeSignedInSession awaits the OIDC token, so a signed-out user who is redirected to /signin still has the original path stored in redirectUrlPath and returns to that entity after login. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@sweta1308
sweta1308 merged commit daad7f2 into main Nov 24, 2026
64 checks passed
@sweta1308
sweta1308 deleted the fix-28295-deep-link-lost-on-login branch November 24, 2026 09:12
sweta1308 added a commit that referenced this pull request Nov 24, 2026
…in (#38545) (#38578)

* Fixes #28295: keep the deep link a signed-out user opened through login

resumeSignedInSession read the location only after awaiting getOidcToken.
With no stored token, initializeAuthState clears isAuthenticating first, so
the router can redirect the protected URL to /signin before that await
returns; the location then read is /signin, nothing is stored, and the user
lands on / after login. Capture the location before the await.

* Restore the deep-link test's mocks even when its assertion fails

* Type the deep-link test's location mock instead of disabling no-explicit-any

(cherry picked from commit daad7f2)
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.

Authentication always redirects users to the main page

2 participants