2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Http\Middleware;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
2023-05-17 18:56:55 +02:00
|
|
|
use BookStack\App\Providers\RouteServiceProvider;
|
2015-07-12 21:01:42 +02:00
|
|
|
use Closure;
|
2021-10-30 22:29:59 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
class RedirectIfAuthenticated
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2021-11-04 23:57:49 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @param string|null ...$guards
|
|
|
|
*
|
2015-07-12 21:01:42 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2021-10-30 22:29:59 +02:00
|
|
|
public function handle(Request $request, Closure $next, ...$guards)
|
2015-07-12 21:01:42 +02:00
|
|
|
{
|
2021-10-30 22:29:59 +02:00
|
|
|
$guards = empty($guards) ? [null] : $guards;
|
|
|
|
|
|
|
|
foreach ($guards as $guard) {
|
|
|
|
if (Auth::guard($guard)->check()) {
|
|
|
|
return redirect(RouteServiceProvider::HOME);
|
|
|
|
}
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
2021-11-04 23:57:49 +01:00
|
|
|
}
|