title: Laravel 5 middlware weird behavior
body: <p>I'm working with Laravel 5.1, and I have been searching the answer for this problem long ago, but I've been not succeed.</p>
  
  <p>The problem takes place when a super-administrator tries to login. The whole login process is implemented in AJAX, so when the login takes place AJAX awaits for the redirection url while the Authentication process is taken by an Auth Controller.</p>
  
  <p>If the request is ok, the a dashboard url is sent back to the ajax, BUT the middleware logs me out once the redirection is performed.</p>
  
  <p>The auth WelcomeController to validate the super-admin looks like this (this works just fine, delivering the propper redirection url):</p>
  
  <pre><code>\Config::set('auth.model', 'App\Super_Admin');
  
      $sadmin = \Auth::createEloquentDriver();
  
      \Auth::setProvider($sadmin-&gt;getProvider());
  
      //Admin verification
      if(\Auth::attempt(['system_admin_user' =&gt; $request-&gt;username, 'password' =&gt; $request-&gt;password])) {
  
          \Auth::user()-&gt;setAttribute('profile','SuperAdmin');
          \Session::set('sadmin_name',\Auth::user()-&gt;system_admin_fullname);
  
          return response()-&gt;json(['login_status' =&gt; 'success', 'redirect' =&gt; 'SuperAdmin/dashboard', 'error' =&gt;'']);
      }
      else {
          return response()-&gt;json(['login_status' =&gt; 'invalid', 'error' =&gt; 'Usuario y/o password invalidos', 'redirect' =&gt; '/']);
      }
  </code></pre>
  
  <p>The function to handle the requests in Middleware is_admin looks like this (not working as intended):</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
  
  if(\Auth::check() &amp;&amp; \Auth::user()-&gt;profile == "SuperAdmin") {
          return redirect('/');
  }
  else {
      return response('Unauthorized.', 401);
  }
  
  return $next($request);
  }
  </code></pre>
  
  <p>I also tried with a different code of the middleware:</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
     if(!\Auth::check() || \Auth::user()-&gt;profile != "SuperAdmin") {
         $this-&gt;auth-&gt;logout();
     }
  
     return $next($request);
  }
  </code></pre>
  
  <p>The route group protected for the admin is defined like this:</p>
  
  <pre><code>Route::group(['middleware' =&gt; ['auth','is_superAdmin']], function() {
  Route::get('SuperAdmin/dashboard','Super_Admin\SuperAdminController@index');
  });
  </code></pre>
  
  <p>Thanks you in advance!</p>