3 years ago

Manually set intended() URL for login

Posted 3 years ago by Pendo

I got another one on this issue, maybe I'm using the wrong approach so let me first explain the situation.

This project has an agenda page containing a number of items, a visitor can click an item to view the details. While logged in users can sign up for these items, a guest can not. So when a guest clicks a button "Sign up", he/she gets prompted with a modal containing a login and register button.

A logged in used would get a popup asking for a confirmation and then making a post-request to one of the routes for adding the user. Obviously, this route is auth-protected but it is in fact never a visible route. After saving the data, the user gets redirected back to the agenda item's detail page.

The issue in this situation is as follows: guests that click the "login" button from the model are redirected to the login form (as expected), however after login they are forwarded to the redirectPath from the AuthController and not the page they came from. From a previous issue I recall that the "intended URL" is set in the auth-middleware,..

So my guess is I'd have to clone this functionality and "Flash" it to the next page? But it seems an overkill to add a function to each controllers contructor (or even method) that saves the current URL? Is there something out of the box to use?

Please sign in or create an account to participate in this conversation.