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

_chris's avatar

TokenMismatchException with logout

Now that logout is a POST request instead of a GET request (in 5.3). If I try to logout after the session has expired I get a TokenMismatchException and am not logged out properly.

Although I prefer it to be a POST maybe the logout doesn't require a CSRF token?

0 likes
6 replies
bestmomo's avatar

Hello,

You must now send a POST request with CSRF token.

<form id="logout-form" action="{{ url('/logout') }}" method="POST">
    {{ csrf_field() }}
</form>
1 like
_chris's avatar

Yes but if I login to my site then go out to the pub, then come back after 2 hours and try to log out I get a TokenMismatchException. This exception stops me from logging out properly so I have to navigate back, refresh the page, and log out again.

In practice this seems like a bit of an issue to me?

XavRsl's avatar
XavRsl
Best Answer
Level 11

Just got the same problem today. Easy fix, edit VerifyCsrfToken class :

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        '/logout'
    ];
}
7 likes

Please or to participate in this conversation.