[8.x] Multiple guards for RedirectIfAuthenticated (#5329)
* Update RedirectIfAuthenticated.php allow the middleware to have the same behavior as https://laravel.com/api/5.8/Illuminate/Auth/Middleware/Authenticate.html#method_authenticate so now the guest middleware have the same footprint as auth ex.`guest:web,admin` instead of creating multiple lines to support different guards. * Update RedirectIfAuthenticated.php
This commit is contained in:
parent
6ca2ecacea
commit
adb7eacf9e
|
@ -16,10 +16,18 @@ class RedirectIfAuthenticated
|
||||||
* @param string|null $guard
|
* @param string|null $guard
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next, $guard = null)
|
public function handle($request, Closure $next, ...$guards)
|
||||||
{
|
{
|
||||||
return Auth::guard($guard)->check()
|
if (empty($guards)) {
|
||||||
? redirect(RouteServiceProvider::HOME)
|
$guards = [null];
|
||||||
: $next($request);
|
}
|
||||||
|
|
||||||
|
foreach ($guards as $guard) {
|
||||||
|
if (Auth::guard($guard)->check()) {
|
||||||
|
return redirect(RouteServiceProvider::HOME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue