Browse Source

Don't return a login page to a JSON request

Currently, any unauthorized API requests that pass through the `auth` middleware get a redirect to the login page. Adding the `wantsJson` flag to the conditional corrects this behavior.
Jacob Bennett 8 years ago
parent
commit
5b3c5f3f4e
1 changed files with 1 additions and 1 deletions
  1. 1 1
      app/Http/Middleware/Authenticate.php

+ 1 - 1
app/Http/Middleware/Authenticate.php

@@ -18,7 +18,7 @@ class Authenticate
     public function handle($request, Closure $next, $guard = null)
     {
         if (Auth::guard($guard)->guest()) {
-            if ($request->ajax()) {
+            if ($request->ajax() || $request->wantsJson()) {
                 return response('Unauthorized.', 401);
             } else {
                 return redirect()->guest('login');