aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Middleware/RedirectIfAuthenticated.php
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2023-06-04 13:19:44 +0200
committerPatrick Spek <p.spek@tyil.nl>2023-06-04 13:19:44 +0200
commitdd66a8e2fbe60c18123dd7245ca68b367367a81c (patch)
tree2e43ccdf89653f8d57beff1cee578498fcd4d851 /app/Http/Middleware/RedirectIfAuthenticated.php
Initial commitHEADmaster
Diffstat (limited to 'app/Http/Middleware/RedirectIfAuthenticated.php')
-rw-r--r--app/Http/Middleware/RedirectIfAuthenticated.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php
new file mode 100644
index 0000000..a2813a0
--- /dev/null
+++ b/app/Http/Middleware/RedirectIfAuthenticated.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use App\Providers\RouteServiceProvider;
+use Closure;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+
+class RedirectIfAuthenticated
+{
+ /**
+ * Handle an incoming request.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
+ * @param string|null ...$guards
+ * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
+ */
+ public function handle(Request $request, Closure $next, ...$guards)
+ {
+ $guards = empty($guards) ? [null] : $guards;
+
+ foreach ($guards as $guard) {
+ if (Auth::guard($guard)->check()) {
+ return redirect(RouteServiceProvider::HOME);
+ }
+ }
+
+ return $next($request);
+ }
+}