]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Middleware/RedirectIfAuthenticated.php
Laravel 8 shift squash & merge (#3029)
[bookstack] / app / Http / Middleware / RedirectIfAuthenticated.php
index 6853809ea9d03b5db7a74a817c6f256ef00d832a..76e64a3b9d6660eece36bdd5762bdd0cac40f202 100644 (file)
@@ -2,45 +2,31 @@
 
 namespace BookStack\Http\Middleware;
 
+use BookStack\Providers\RouteServiceProvider;
 use Closure;
-use Illuminate\Contracts\Auth\Guard;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
 
 class RedirectIfAuthenticated
 {
-    /**
-     * The Guard implementation.
-     *
-     * @var Guard
-     */
-    protected $auth;
-
-    /**
-     * Create a new filter instance.
-     *
-     * @param Guard $auth
-     *
-     * @return void
-     */
-    public function __construct(Guard $auth)
-    {
-        $this->auth = $auth;
-    }
-
     /**
      * Handle an incoming request.
      *
-     * @param \Illuminate\Http\Request $request
-     * @param \Closure                 $next
-     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @param  string|null  ...$guards
      * @return mixed
      */
-    public function handle($request, Closure $next)
+    public function handle(Request $request, Closure $next, ...$guards)
     {
-        $requireConfirmation = setting('registration-confirmation');
-        if ($this->auth->check() && (!$requireConfirmation || ($requireConfirmation && $this->auth->user()->email_confirmed))) {
-            return redirect('/');
+        $guards = empty($guards) ? [null] : $guards;
+
+        foreach ($guards as $guard) {
+            if (Auth::guard($guard)->check()) {
+                return redirect(RouteServiceProvider::HOME);
+            }
         }
 
         return $next($request);
     }
-}
+}
\ No newline at end of file