3 weeks ago

Redirect unauthenticated user dependant on guard

Posted 3 weeks ago by cluel3ss

I use both standard auth and custom auth guard labelled business_user in my app. All my "business" routes are prefixed with business. in the route names and are attached to the middleware auth:business_user which ensures they are logged in using a business_user account before they can proceed.

When a business_user session times out they get redirected to the login screen, however the login screen they are shown in the normal login screen. I have a separate one for business_user auth.

How can I edit the Authenticate.php middleware to be "aware" of which routes they tried to access and route them accordingly?

Here is what the current Authenticate redirectTo method looks like (its pretty vanilla)

    protected function redirectTo($request)
        if (! $request->expectsJson()) {
            return route('customer.login');

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