Skip to content

[6.x] Redirect to intended URL after CP login#14560

Open
jasonvarga wants to merge 3 commits into6.xfrom
fix-cp-login-redirect
Open

[6.x] Redirect to intended URL after CP login#14560
jasonvarga wants to merge 3 commits into6.xfrom
fix-cp-login-redirect

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

Summary

When an unauthenticated user visits a CP URL (e.g. /cp/collections), they are redirected to the login page. After logging in, they were being sent to the CP home page rather than the page they originally tried to reach.

The root cause: AuthenticationException redirected via redirect()->route('statamic.cp.login'), which doesn't store the intended URL. LoginController::authenticated() was already calling redirect()->intended(...), but the session never had a target to recall, so it always fell back to the home page.

Changes

  • AuthenticationException now redirects via redirect()->guest(route('statamic.cp.login')), which stores the originally requested URL in the session as url.intended.
  • Removed dead referer query plumbing from LoginController (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 still desirable 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.

Test plan

  • Visit /cp/collections while logged out, log in, confirm you land on /cp/collections
  • Visit /cp/auth/login directly, log in, confirm you land on the CP home
  • Log in with two-factor enabled and confirm the challenge page renders correctly without a hard reload

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.
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