title: Laravel 419 Error handling - Requires two attempt for login
body: <p>The application is okay and works perfectly. But the issue that we were facing firstly was if a user logged out and tried to log in the next day from a saved/pinned browser tab (route: https://domain/login) the page redirected to the 419 (expired) page. And the user had to use the browser's back button to go back and log in again. So we used redirection to the handler.</p>
  <pre><code>$this-&gt;renderable(function (\Exception $e) {
       if ($e-&gt;getPrevious() instanceof \Illuminate\Session\TokenMismatchException) {
       return redirect()-&gt;away(request()-&gt;getSchemeAndHttpHost());
    };
  });
  </code></pre>
  <p>So, on the first login attempt, the handler redirects immediately to the main domain (root path), and because of having no auth session, it is redirected to the https://domain/login page again. So users need to attempt to log in again (2nd time). It's so annoying.</p>
  <p>We searched and tested different solutions from the answers to similar issues. On config/session.php we changed multiple things as,</p>
  <pre><code>'path' =&gt; '/;samesite=none',
  
  'lifetime' =&gt; env('SESSION_LIFETIME', 420),
  
  'domain' =&gt; env('SESSION_DOMAIN', null), (not set)
  
  'secure' =&gt; env('SESSION_SECURE_COOKIE') (not set),
  
  'same_site' =&gt; 'lax',
  </code></pre>
  <p>So, the question is, if the token is already expired why the exception handler doesn't simply do its attempt to redirect when the browser opens, the saved/pinned tab is already loaded? Is that handler not working on routes? In that case, how to check if the page is expired or for the login route? Please help me with a solution.</p>