My tip:
https://talltips.novate.co.uk/laravel/csrf-and-expired-logout-forms
I'll have to try that scenario and adjust...
The problem is that although you are logged in, the token posted as csrf is no longer valid.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all, hopefully someone can help please.
I am encountering an issue where I get a 419 token mismatch on logout when the ordinary 2 hour session has expired but I am still authenticated as I logged in with remember me selected. This is not occurring if I have not selected remember me as I have the below check in the VerifyCsrfToken middleware.
if (!auth()->check() && $request->route()->named('logout')) {
$this->except[] = route('logout');
}
return parent::handle($request, $next);
This does not catch the logout request when there this a remember token cookie as auth()->check() is returning true. Does anyone have any ideas what could be causing this? Thanks in advance!
Please can you try this variant. If its ok, then I'll update the post. It seems to work in my testing.
class VerifyCsrfToken extends Middleware
{
public function handle($request, Closure $next)
{
if($request->route()->named('logout')) {
if (!Auth::check() || Auth::guard()->viaRemember()) {
$this->except[] = route('logout');
}
}
return parent::handle($request, $next);
}
}
viaRemember() is only true for the very first request cycle. So the code ignores all requests that are not for logout, and then adds logout to the except list if the user is not authenticated OR they just logged in with viaRemember()
Please or to participate in this conversation.