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

MuhammadZaheerUdDin's avatar
  1. In App/Exception/Handler.php
  2. Use Illuminate\Auth\AuthenticationException;
  3. In render function add this instead of "return parent::render($request, $exception);"

public function render($request, Exception $exception) {

return $request->expectsJson()
        ? response()->json(['message' => $exception->getMessage()], 401)
        : redirect()->guest(route('login', ['account' => $request->route('account')]));

}
maker's avatar

This happens to me a lot, it seems that the cookies don't match the file sessions after a deployment. Presumably because when I deploy using docker the memcached sessions are cleared and the cookie is now invalid.

Personally I use a standard form submission and no AJAX so the 419 really threw me off.

I think what I have to do after reading over this thread is to try running php artisan cache:clear because when I make a code change my composer script is not run.

Previous

Please or to participate in this conversation.