title: Laravel Edit Auth Middleware
body: <p>I'm trying to edit the main <code>Authenticate.php</code> middleware, but when I add the following, I get an error </p>
  
  <blockquote>
    <p>app.app has redirected you too many times</p>
  </blockquote>
  
  <p>My intent here is to edit the auth middleware to check if the user has a username. This would prevent someone from exiting the registration page and then simply going into a secure portion of the website.</p>
  
  <p>Auth Middleware:</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      if ($this-&gt;auth-&gt;guest()) {
          if ($request-&gt;ajax()) {
              return response('Unauthorized.', 401);
          } else {
              return redirect()-&gt;guest('/');
          }
      }
  
      // This is the modified portion. Check for a username, if one is found, complete 
         the request, otherwise redirect back to the oauth page.
  
      if (Auth::user()-&gt;username)
      {
          return $next($request);  
      }
  
      return redirect()-&gt;route('oauth.oauth')-&gt;with('user' , Auth::user()-&gt;id);
  
  }
  </code></pre>