ldc-legaulois/app/Http/Middleware/Authenticate.php

39 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2020-07-23 10:29:36 +02:00
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
2024-01-10 14:49:46 +01:00
use Illuminate\Http\Request;
2021-03-08 11:24:20 +01:00
use Illuminate\Support\Facades\Session;
2020-07-23 10:29:36 +02:00
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*/
2024-01-10 14:49:46 +01:00
protected function redirectTo(Request $request): ?string
2020-07-23 10:29:36 +02:00
{
2024-01-10 14:49:46 +01:00
$logins = [
2024-07-05 16:34:57 +02:00
'backend' => route('bo.login'),
2026-09-25 16:25:31 +02:00
'club' => route('club.login'),
2024-01-10 14:49:46 +01:00
];
2026-09-25 16:25:31 +02:00
if (! $request->expectsJson()) {
2024-01-10 14:49:46 +01:00
// * Notify must login
Session::flash('warning', trans('Veuillez vous connecter pour continuer'));
2024-01-10 14:49:46 +01:00
foreach ($request->route()->gatherMiddleware() as $middleware) {
if (\is_string($middleware) and strpos($middleware, 'auth:') !== false) {
$route = $logins[str_replace('auth:', '', $middleware)] ?? null;
if ($route) {
return $route;
}
2021-03-08 11:24:20 +01:00
}
}
2026-09-25 16:25:31 +02:00
2026-09-25 14:24:39 +02:00
return route('fo.home.show');
}
2026-09-25 16:25:31 +02:00
2024-01-10 14:49:46 +01:00
return null;
2020-07-23 10:29:36 +02:00
}
}