Home > Net >  How do I redirect from a Subscriber without loosing page data?
How do I redirect from a Subscriber without loosing page data?

Time:09-20

I have created a Plugin which enables securing pages with a password. The Plugin listens to GenericPageLoadedEvent and HttpCacheHitEvent and checks if a password for the accessed page has been set. If a password was set and the session wasn't logged into that page, the subscriber redirects the request to my login page.

Here is the problem: The login page is missing all the navigations. The common solution to combat this is to load a generic page. But that also triggers the events the plugin is already listening to and causes a loop.

Is there any way around this problem? Is it possible to only load the navigations?

CodePudding user response:

So your login page is a route you registered in your plugin? Why not check the route name in your event listeners and early return if it's your own login page route that was requested?

$request = $event->getRequest();

if ($request->attributes->get('_route') === 'name.of.your.login.route') {
    return;
}

// rest of the logic in your event listeners

  • Related