title: How to get sessions working in Laravel api routes?
body: <p>I'm trying to get my sessions working for API-Routes. On Web-Routes everything is fine, but the Moment I try to use it on API-Routes the Session is empty. </p>
  
  <p>I know APIs should be stateless but I just communicate with an external API and my Laravel instance is just the frontend. </p>
  
  <p>So my authentification is just a simple <code>Session::put('userData', $response-&gt;data);</code> after the successful request to the login endpoint of the API. In there some data about name, email, some default data and the auth token for the user.</p>
  
  <p>The last one is important because I'd like to access some endpoints via AJAX (axios) and I need to send the saved auth token to the API to get things working. But everything is broken at the moment I try to guard the API-Routes with my <code>RedirectIfUnauthenticated</code>-Middleware. It always redirects me to the login page, because the session is empty. </p>
  
  <p>If I remove it, I get to the Controller but the session is still empty and I can't add the auth token to the api request.</p>
  
  <p>I think I do something fundamentally wrong here. So maybe someone can help here.</p>
  
  <p>I already tried to add <code>\Illuminate\Session\Middleware\StartSession::class,</code> to the <code>$middlewareGroups</code> api section, but it seems to reset all session data so I get logged out. But maybe I do something wrong here too.</p>