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

chrisgrim's avatar

Session expires but Nav bar doesnt update to reflect

Hi All,

I was wondering if anyone else has had an issue where their session expires if they leave their browser open but the nav bar doesn't update to show that I have been logged out. So when I click on something it gives me an error. Does Laravel have any built in way to refresh the browser page when the session has expired?

0 likes
5 replies
jlrdw's avatar

That's expected Behavior no different than if you were on a page that required authorization.

You can probably catch the error and redirect to a friendly page with a link to go back to login page.

chrisgrim's avatar

Hi @snapey

I have a middleware for admin

public function handle($request, Closure $next)
    {
        if (auth()->user()->Admin())
        {
            return $next($request);
        }
        return redirect('/');
    }

This is what gives me the error. I will look into the laravel-caffeine too!

Snapey's avatar
Snapey
Best Answer
Level 122

adjust your middleware so that if the user is not logged in, you redirect them to the login route

public function handle($request, Closure $next)
{
    if (Auth::check() && Auth::user()->Admin())
    {
        return $next($request);
    }
    return redirect('/login');
}

Adjust for your login route or use named routes

Please or to participate in this conversation.