title: Laravel 4 AUTH via AJAX, possible session issue
body: <p>I've done it in previous projects using Sentry 2, but I can't get it to work with the built-in Auth functionality.</p>
  
  <p>User store method:</p>
  
  <pre><code>public function store()
  {
      $validation = new Services\Validators\User;
  
      if ($validation-&gt;passesForStore()) {
          // Create a new user
          $user = new User;
          $user-&gt;name     = Input::get('name');
          $user-&gt;password = Input::get('password');
          $user-&gt;email    = Input::get('email');
          $user-&gt;save();
  
          // Authenticate the user
          Auth::loginUsingId($user-&gt;id);
  
          return JSend::success([
              'redirect' =&gt; URL::action('VaultController@index')
          ]);
      }
  
      // Provide a custom message for an e-mailaddress that's already in use
      $message = '';
      if ($validation-&gt;hasFailed('email', 'unique')) {
          $message = 'This e-mailaddress has already been taken';
      }
  
      return JSend::fail([
          'failed' =&gt; $validation-&gt;failedFields(),
          'message' =&gt; $message
      ]);
  }
  </code></pre>
  
  <p>The AJAX response handler:</p>
  
  <pre><code>// Redirect to given URL
  if (typeof response.data.redirect != 'undefined') {
      window.location = response.data.redirect;
  }
  </code></pre>
  
  <p>The user is successfully created, placing an <code>Auth::check();</code> directly after the <code>loginUsingId</code> results in <code>true</code> but as soon as the page is redirected by <code>window.location</code>, <code>Auth::check()</code> results in false and the user is not logged in, not even when manually navigating to a different page.</p>
  
  <p>App.session settings:</p>
  
  <pre><code>'lifetime' =&gt; 120,
  'expire_on_close' =&gt; true,
  </code></pre>
  
  <p>Bare in mind that the login method works in a similar way but doesn't work either!
  (it does work without the use of AJAX)</p>
  
  <p><strong>=== UPDATE ===</strong></p>
  
  <p>Life just got a little weirder. <strike>I can now login using my login and register methods.
  What changed? I added a vhost alias for my former localhost project and logging in seemed
  to work fine. (Sounds to me like an environment issue?).</strike></p>
  
  <p>What doesn't work however is logging out. I created the following route for test purposes:</p>
  
  <pre><code>Route::get('logout', function(){
      Auth::logout();
      Session::flush();
  
      dd(Auth::check());
  });
  </code></pre>
  
  <p>The result is, as expected, <code>false</code>. However! If I then go to my login page I get redirected. Visiting my other debug route below results in <code>true</code> which makes absolutely
  no sense at all. The user was not logged in using the 'remember' flag.</p>
  
  <pre><code>Route::get('authenticated', function(){
      dd(Auth::check());
  });
  </code></pre>
  
  <p>Any input is highly appreciated at this point :)</p>
  
  <p><strong>=== UPDATE 2 ===</strong></p>
  
  <p>It seems the previous successful attempt was just a fluke. Logging in, or logging out after I manually logged myself in doesn't work.. Any way to debug this kind of black magic?</p>
  
  <p><strong>=== UPDATE 3 ===</strong></p>
  
  <p>Today I tried my app once more and was presented with an can't write to session file xxxx error. I checked my storage/sessions folder and found that no such file existed.</p>
  
  <p>I emptied the storage/sessions folder, cleared all cache, and weird enough the login and
  logout problems I had before are gone.</p>
  
  <p>Even though the primary issue is solved (for now) I would still like to find out what caused this problem in the first place</p>