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

NegCon's avatar

"This page has expired" message on pages with Livewire component after a few hours if user is logged in

I currently have a strange behaviour with my website. When a user is logged in, the following message appears after about 2 to 3 hours on pages where a Livewire component is built in and when I want to use it:

"This page has expired. Would you like to refresh the page?"

Reloading the page does not help. The message still appears when I want to use a Livewire component.

On pages where no Livewire component is integrated, however, everything works as it should and the respective user is recognised by Laravel as logged in.

When logging in, I use remember true (remember-me option). It seems that Livewire somehow does not recognise this. If no user is logged in, the error does not occur. But I have no idea where the error could be.

0 likes
9 replies
Snapey's avatar

Livewire will not log the user in.

When you are logged out on a regular page, and reload the page, the user is redirected to the login route, which then inspects remember me, automatically logs the user in, and sends them back to the original page.

When you try to refresh a livewire component and the user is logged out, they are not redirected to login.

NegCon's avatar

First of all, thanks for the help. I had already looked in the Livewire documentation, I mean even in the linked article. My main problem is that the message does not disappear by reloading the page.

If a user has logged in to the website about 2 - 3 hours ago and then some action is to be performed by a Livewire component, the said message appears that the page would have expired.

Immediately after logging in, everything still works as it should, but after a few hours the error message appears. Reloading the website doesn't help either, the message that the page has expired keeps coming up. If I then log out and reload the page, the Livewire components work permanently. As soon as I log on again, however, after an estimated 2 - 3 hours, the error message appears again when I want to use a Livewire component, no matter how often I reload the page.

As an example, I have programmed a listing with Livewire that includes pagination. When the page is loaded for the first time, the first page is of course always displayed. If you then click on the link for another page (e.g. page 2 of the listing), the error message appears that the page has expired. If I then click OK on the message box, the page reloads and page 1 is displayed again. If I then click on the link again for another page (e.g. page 2 of the listing again), the error message appears again and if I click on OK again, everything reloads again and you are back on page 1, etc.

Maybe there is something wrong with the deployment hash, but then the question arises why the problem only occurs when a user has been logged on to the website for a few hours. The user session itself does not seem to have expired, because in web pages of my project that do not use Livewire, the user login is still recognised and processed by Laravel without any problems.

Snapey's avatar

The user session itself does not seem to have expired, because in web pages of my project that do not use Livewire, the user login is still recognised and processed by Laravel without any problems.

The user's session WILL have expired but the remember me option seamlessly logs them back in

NegCon's avatar

That sounds plausible. What I don't understand is why Livewire, at least in my case, doesn't recognise the new user session after reloading the page. The only solution would then be for users to log out and log in again to get around the problem (e.g. by automatically logging them out of Laravel and automatically redirecting them to the login page when Livewire detects the session as expired). But then the whole remember me option doesn't make sense anymore. The only solution I see would be to dramatically extend the user session runtime.

Sorry if I sound a bit silly, I just want to understand how this is handled internally with the user sessions and whether this behaviour is really intended. In any case, I am grateful for the attempts at explanation. :)

Snapey's avatar

@NegCon livewire polling would keep the session going indefinitely, and you would only need to do it about every 10 minutes

1 like
jamesautodude's avatar

I know this is kinda old but just in case someone comes across this to do with the page expired message when you delete sessions or other related issues, you can do this in Livewire 3:

Make sure livewireScripts is called BEFORE the code exactly like below, and put this in your main app layout file:

@livewireScripts
<script>
let isRedirecting = false; // Flag to prevent multiple redirects

Livewire.hook('request', ({ fail }) => {
    fail(({ status, preventDefault }) => {
        if (status === 419) {
            preventDefault(); // Stop Livewire's default behavior
            
            if (!isRedirecting) {
                isRedirecting = true; // Set the flag to true
                window.location.href = '/login'; // Redirect to login route
            }
        }
    });
});
</script>

Seems like this kinda works where it'll redirect back to login and reauth without any popups/messages, then go back to the original page. You'll see some errors recorded in the console, but seems to still do the right thing for now and nobody will see that anyways...

This is especially for wire:poll situations where you kick the user's session while the user is on the page

2 likes
nindo's avatar

Hello, In my case, it was a wrong SESSION_DOMAIN value in .env file. Using the right domain fixed the issue.

Please or to participate in this conversation.