Skip to content

Commit

Permalink
Two Files updated in middleware folder authenticate and redirectifaut…
Browse files Browse the repository at this point in the history
…henticated
  • Loading branch information
RishikantSri committed May 16, 2023
1 parent 79fbe98 commit d0bbbf2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

- **[Multi Auth: Laravel 9 Initial Installation, Admin, Manager, Client Models ](https://github.com/RishikantSri/multiauth/commit/ec5873e5ffa943623d74f3dcad1d35067a61b091)**


- **[Multi Auth: Models Updated, Gaurds, provider etc updated in Auth.php file ](https://github.com/RishikantSri/multiauth/commit/79fbe989a7e6ac0b2b7a3cfd9c472d3f10d92104)**




11 changes: 11 additions & 0 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@ class Authenticate extends Middleware
*/
protected function redirectTo($request)
{

if (! $request->expectsJson()) {
if($request->routeIs('admin.*')){
return route('admin.login');
}
elseif($request->routeIs('manager.*')){
return route('manager.login');

}
elseif($request->routeIs('client.*')){
return route('client.login');
}
return route('login');
}
}
Expand Down
16 changes: 13 additions & 3 deletions app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ 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);
if($guard === 'admin'){
return redirect()->route('admin.home');
}
}
elseif($guard === 'manager'){
return redirect()->route('manager.home');
}
elseif($guard === 'client'){
return redirect()->route('client.home');
}

return redirect()->route('user.home');
// return redirect(RouteServiceProvider::HOME);
}


return $next($request);
}
Expand Down

0 comments on commit d0bbbf2

Please sign in to comment.