Repository navigation
Fixes #28295: keep the deep link a signed-out user opened through login - #38545
Conversation
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.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
UI browser testsRan: 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%)
|
Code Review ✅ Approved 🟡 Medium riskCapturing 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 VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
…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)
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
redirectUrlPathcookie. On a cold load with no stored token, the cookie was sometimes never written.Cause.
resumeSignedInSessionread the current location only afterawait getOidcToken(). With no token,initializeAuthStateclearsisAuthenticatingfirst. The router then mounts, andUnAuthenticatedAppRouterredirects the protected URL to/signinwhile 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 loginPermissionProviderhas 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'sonRefreshStart, 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:
High-level design:
N/A — small change (2 files).
Tests:
Use cases covered
/signin, signs in, and returns to that URL with its query string./still lands on/.onRefreshStart, refresh failure) still store the current location.Unit tests
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 holdsgetOidcTokenpending, moves the router to/signin, then resolves with no token, and asserts that the original path and query string are stored.handleStoreProtectedRedirectPath()call and passes with the fix.yarn test src/components/Auth/AuthProviders/AuthProvider.test.tsx: 50 passed, 0 failed.AuthProvider.tsx: 80.99% lines (whole file). All changed lines are covered.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
make playwright_affectedselects broad permissions/smoke specs becauseAuthProvider.tsxis shared. Locally,Auth/Login.spec.tsstops inauth.setup.tswithHTTP 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.mainpasses 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 viayarn starton:3000. A Playwright script opens/table/sample_data.ecommerce_db.shopify.agent_performance_summary/schemain a fresh, signed-out browser context. It records theredirectUrlPathcookie on/signin, signs in as admin through the form, and checks the final URL./signin/instead of the tablemainEvery failure on
mainwas 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)The test forces the race: the token lookup is still pending while the router moves to
/signin. Onmainthe 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 theredirectUrlPathcookie:After signing in as admin, the browser lands on the table itself, not the home page:
3. Repeated browser runs: see the table above.
mainlost 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:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill 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 infinally.3f5d0359c7cafter it only replaces the test'sas anycast withjest.requireMock<jest.Mock>.🤖 Generated with Claude Code