Answer the question
In order to leave comments, you need to log in
Laravel Token mismatch exception?
There is a page, the page has a lot of functionality through ajax. All post requests are checked against csrf. After a certain time, if you do not reload the page, Ajax requests stop working because the token has changed.
What to do in this case? Can I remove ajax requests from the check?
Answer the question
In order to leave comments, you need to log in
It's just that the lifetime of the token is set to 2 hours by default. You can see this in Illuminate\Foundation\Http\Middleware\VerifyCsrfToken in the addCookieToResponse method.
protected function addCookieToResponse($request, $response)
{
$response->headers->setCookie(
new Cookie('XSRF-TOKEN', $request->session()->token(), time() + 60 * 120, '/', null, false, false)
);
return $response;
}
protected function addCookieToResponse($request, $response)
{
$response->headers->setCookie(
new Cookie('XSRF-TOKEN', $request->session()->token(), time() + Config::get("session.lifetime")*60, '/', null, false, false)
);
return $response;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question