Skip to content

[6.x] Fix login redirects#14560

Merged
jasonvarga merged 11 commits into6.xfrom
fix-cp-login-redirect
Apr 29, 2026
Merged

[6.x] Fix login redirects#14560
jasonvarga merged 11 commits into6.xfrom
fix-cp-login-redirect

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

@jasonvarga jasonvarga commented Apr 27, 2026

Summary

When an unauthenticated user visits a protected URL, they're redirected to the login page. After logging in, they should land back on the URL they originally tried to reach — but they were being sent to the home page (CP or site) instead.

This affected every login method on both the CP and the frontend: regular password login, passkey login, two-factor challenge (TOTP and recovery code), and the two-factor setup flow.

Changes

CP

  • AuthenticationException now redirects via redirect()->guest(...), which stores the originally requested URL in the session as url.intended.
  • LoginController::authenticated() already called redirect()->intended(...), which now has a target to recall.
  • Removed dead referer query plumbing (getReferrer(), the referer Inertia prop, and the conditional in redirectPath()). The Inertia login form never POSTed a referer field, so the server-side check was always null.
  • Login.vue now hard-reloads to page.url (the URL Inertia ended up at after following the server's redirect) instead of the unused props.referer. The full page load is preserved so the destination CP page boots with all its initial props. The two-factor challenge early return in onSuccess is preserved so that flow stays an Inertia transition.
  • The passkey and two-factor challenge controllers now also honor url.intended (previously they used a referer form input that the JS never sent for passkey, and a hand-rolled session key for 2FA).

Frontend

  • User/LoginController, User/PasskeyLoginController, TwoFactorChallengeController, TwoFactorSetupController, and User/TwoFactorAuthenticationController all route through url.intended instead of the short-lived login.redirect session key introduced last week.
  • The auth middleware already redirects via redirect()->guest(...), so frontend forms without an explicit _redirect input now land on the originally requested URL after login.
  • Explicit _redirect form inputs still win — they're written into url.intended so they survive multi-step flows (e.g. login → 2FA challenge, login → 2FA setup).

Internal

  • The parallel login.redirect session key has been removed entirely. Everything now uses Laravel's standard url.intended, accessed via redirect()->setIntendedUrl(), redirect()->getIntendedUrl(), and redirect()->intended().
  • login.redirect was only introduced last week (unreleased), so removing it is not a compatibility break.
  • CP subclasses now override only the default fallback URL via small defaultRedirectPath() / defaultRedirectUrl() hooks, instead of duplicating the whole resolution logic.

jasonvarga and others added 7 commits April 27, 2026 17:08
Use redirect()->guest() in AuthenticationException so Laravel stores
the originally requested URL in the session. The existing
redirect()->intended() call in LoginController will then send the user
back to the page they were trying to reach instead of the CP home.

Also drops dead `referer` plumbing in LoginController and the Login.vue
component now hard-reloads to page.url (the URL Inertia followed the
server redirect to) instead of the unused props.referer.
The `referer` POST param path was dead with the Inertia form and was
removed in this branch. The intended-URL flow is covered by the
adjacent `it_redirects_to_intended_url` test.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the parallel `login.redirect` session key with Laravel's standard
`url.intended` for login, passkey, 2FA challenge, and 2FA setup flows. As a
result, frontend forms without an explicit `_redirect` input now redirect to
the URL the auth middleware bounced from.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jasonvarga jasonvarga changed the title [6.x] Redirect to intended URL after CP login [6.x] Redirect to intended URL after login (CP and frontend) Apr 29, 2026
jasonvarga and others added 4 commits April 29, 2026 15:22
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previously the dropdown's logout link asked the controller to redirect
to /cp after logout. That unauthenticated request to /cp triggered the
CP auth middleware, which restashed /cp into url.intended on the new
session. A subsequent frontend login would then consume that stale URL
and land the user back in the CP.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The frontend RedirectIfTwoFactorSetupIncomplete middleware previously
threaded the original URL through a referer query string, but the
TwoFactorSetupController had been switched to read url.intended from
the session — leaving the query string dead and dropping the original
URL for already-authenticated users bounced into setup. Both middlewares
now stash the URL via setIntendedUrl, and the CP setup controller reads
it back via getIntendedUrl, keeping CP and frontend on the same
mechanism.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The _redirect short-circuit returned early without pulling url.intended
from session, which could leave a stale value behind when both were set.
Pull it up front so it's consumed regardless of which path wins.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jasonvarga jasonvarga changed the title [6.x] Redirect to intended URL after login (CP and frontend) [6.x] Fix login redirects Apr 29, 2026
@jasonvarga jasonvarga merged commit 1a8dd94 into 6.x Apr 29, 2026
19 checks passed
@jasonvarga jasonvarga deleted the fix-cp-login-redirect branch April 29, 2026 20:37
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.

1 participant