How To Avoid TokenMismatchException On Logout

Websolutionstuff | Jun-29-2020 | Categories : Laravel

Many times we faced a Tokenmismatch error in laravel. This error occurs If you stay too long time on one form or if your system stays idle or if you are not active on your computer, and then again try to fill this form.

At that time you may get a TokenMismatchException error because the CSRF token won’t be the same. recently many times we found this problem in logout time. So, In this example, we will see you how to avoid it.

Normally, if you are not active for a long time in your system then you will get errors like the below screen print.

tokenmismatch

 

 

To avoid the TokenMismatchException error, we may add exceptions for the URLs that we don’t want to have CSRF protection. There are special array for that in app/Http/Middleware/VerifyCsrfToken.php

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

So what we need to do, is just add logout into this array.

protected $except = [
    '/logout'
];

If you want to add more URLs then you can add them here.

 


You might also like:

Recommended Post
Featured Post
How To Render Charts In React: using react-chartjs-2 and Chart.js
How To Render Charts In React:...

​​React is a really cool tool that helps programmers make awesome user interfaces using JavaScript.  When it com...

Read More

Jul-26-2023

How To Show Loading Spinner In Ajax jQuery
How To Show Loading Spinner In...

In this article, we will see how to show loading spinner in ajax jquery. Using ajaxStart() and ajaxStop() method we...

Read More

Jul-06-2022

How to Add and Delete Rows Dynamically using jQuery
How to Add and Delete Rows Dyn...

In this article, we will see how to add and delete rows dynamically using jquery. Also, we will see without&nb...

Read More

Jan-02-2021

How To Import Export Excel & CSV File In Laravel 10
How To Import Export Excel & C...

In this article, we will see how to import and export Excel & CSV files in laravel 10. Here, we will learn about lar...

Read More

Mar-08-2023