Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ethar's avatar
Level 5

prevent showing login page, after logi

i have multi guard, i want to prevent showing login page after user is logged-in and hit browser back button. i edited RedirectIfAuthenticated Class as below

    public function handle(Request $request, Closure $next, string ...$guards): Response
    {
        $guards = empty($guards) ? [null] : $guards;
        foreach ($guards as $guard) {
            if ($guard == 'students' && Auth::guard($guard)->check()) {
                return redirect(RouteServiceProvider::STUDENTS);
            }
            if (Auth::guard($guard)->check()) {
                return redirect(RouteServiceProvider::HOME);
            }
        }
        return $next($request);
    }

but still not working

0 likes
1 reply
aleahy's avatar

The problem is your browser is probably caching the content, so is not even hitting your middleware. If you try setting the cache content to no-cache and no-store, does that solve your problem?

Please or to participate in this conversation.