Last change
on this file since dfae77e was dfae77e, checked in by Igor Danilovski <igor_danilovski@…>, 2 years ago |
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | namespace App\Http\Middleware;
|
---|
4 |
|
---|
5 | use App\Enum\UserType;
|
---|
6 | use App\Providers\RouteServiceProvider;
|
---|
7 | use Closure;
|
---|
8 | use Illuminate\Http\Request;
|
---|
9 | use Illuminate\Support\Facades\Auth;
|
---|
10 |
|
---|
11 | class RedirectIfAuthenticated
|
---|
12 | {
|
---|
13 | /**
|
---|
14 | * Handle an incoming request.
|
---|
15 | *
|
---|
16 | * @param \Illuminate\Http\Request $request
|
---|
17 | * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
---|
18 | * @param string|null ...$guards
|
---|
19 | * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
---|
20 | */
|
---|
21 | public function handle(Request $request, Closure $next, ...$guards)
|
---|
22 | {
|
---|
23 | $guards = empty($guards) ? [null] : $guards;
|
---|
24 |
|
---|
25 | foreach ($guards as $guard) {
|
---|
26 | if (Auth::guard($guard)->check()) {
|
---|
27 | $role = Auth::check() ? Auth::user()->type : '';
|
---|
28 | return match ($role) {
|
---|
29 | UserType::ARTIST->value => redirect(RouteServiceProvider::ARTIST_HOME),
|
---|
30 | UserType::ORGANIZER->value => redirect(RouteServiceProvider::ORGANIZER_HOME),
|
---|
31 | UserType::MANAGER->value => redirect(RouteServiceProvider::MANAGER_HOME),
|
---|
32 | default => redirect(RouteServiceProvider::HOME),
|
---|
33 | };
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | return $next($request);
|
---|
38 | }
|
---|
39 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.