Token mismatch exception only on every first laravel 5.1 attempt

Every time I first register in my application after an hour or so or on each new device, I get a token mismatch exception. But when I try again right after the problem goes away. I use 755 for storage / framework / sessions. I have the same problem on my local box with a short box box, as well as onmy Digital Ocean LAMP. Any ideas?

+4
source share
2 answers

The problem is that the CSRF token has expired and your browser needs a new token to request a POST. The default expiration time in Laravel is 2 hours.

, https://laracasts.com/discuss/channels/general-discussion/crsf-checked-before-auth

:

//Handler.php Exception: TokenMismatchException

   /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($e instanceof \Illuminate\Session\TokenMismatchException) {
            return redirect('/')->with('message', 'Sorry, your session seems to have expired. Please login again.');
        }

        if ($e instanceof ModelNotFoundException) {
            $e = new NotFoundHttpException($e->getMessage(), $e);
        }

        return parent::render($request, $e);
    }
0
-1

Source: https://habr.com/ru/post/1598306/


All Articles