aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Middleware/RedirectIfAuthenticated.php
diff options
context:
space:
mode:
authorFrankie B <git@diskfloppy.me>2023-06-13 21:59:16 +0100
committerFrankie B <frankieraybrown@gmail.com>2023-06-14 22:15:44 +0100
commita464ef4c0e3ce235fb1da70dfb282449beeeac80 (patch)
tree4708f5c996376dd94f2cc49f7d16dc80eef1a4df /app/Http/Middleware/RedirectIfAuthenticated.php
parent44db6ce1d9cfdca7e175cb74ee7d818b94571bc4 (diff)
Initialize laravel app
Diffstat (limited to 'app/Http/Middleware/RedirectIfAuthenticated.php')
-rw-r--r--app/Http/Middleware/RedirectIfAuthenticated.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php
new file mode 100644
index 0000000..afc78c4
--- /dev/null
+++ b/app/Http/Middleware/RedirectIfAuthenticated.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use App\Providers\RouteServiceProvider;
+use Closure;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Symfony\Component\HttpFoundation\Response;
+
+class RedirectIfAuthenticated
+{
+ /**
+ * Handle an incoming request.
+ *
+ * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
+ */
+ public function handle(Request $request, Closure $next, string ...$guards): Response
+ {
+ $guards = empty($guards) ? [null] : $guards;
+
+ foreach ($guards as $guard) {
+ if (Auth::guard($guard)->check()) {
+ return redirect(RouteServiceProvider::HOME);
+ }
+ }
+
+ return $next($request);
+ }
+}