Commit 703197e2 authored by Joseph Silber's avatar Joseph Silber

Allow passing multiple gaurds to the auth middleware

parent 8aa5af73
......@@ -12,12 +12,15 @@ class Authenticate
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @param string ...$guards
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
public function handle($request, Closure $next, ...$guards)
{
if (Auth::guard($guard)->guest()) {
if ($this->check($guards)) {
return $next($request);
}
if ($request->ajax() || $request->wantsJson()) {
return response('Unauthorized.', 401);
} else {
......@@ -25,6 +28,24 @@ class Authenticate
}
}
return $next($request);
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return bool
*/
protected function check(array $guards)
{
if (empty($guards)) {
return Auth::check();
}
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return true;
}
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment