2020-10-21 15:26:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-02 12:09:46 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-10-21 15:26:21 +02:00
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
2023-08-21 10:22:07 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-08-16 10:36:05 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-10-21 15:26:21 +02:00
|
|
|
|
|
|
|
|
class Authenticate extends Middleware
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the path the user should be redirected to when they are not authenticated.
|
|
|
|
|
*/
|
2023-08-21 10:22:07 +02:00
|
|
|
protected function redirectTo(Request $request): ?string
|
2020-10-21 15:26:21 +02:00
|
|
|
{
|
2023-08-16 10:36:05 +02:00
|
|
|
$logins = [
|
2026-10-02 12:09:46 +02:00
|
|
|
'backend' => route('bo.login'),
|
2023-08-16 10:36:05 +02:00
|
|
|
];
|
2026-10-02 12:09:46 +02:00
|
|
|
if (! $request->expectsJson()) {
|
2023-08-16 10:36:05 +02:00
|
|
|
// * Notify must login
|
|
|
|
|
Session::flash('warning', trans('Veuillez vous connecter pour continuer'));
|
|
|
|
|
|
|
|
|
|
foreach ($request->route()->gatherMiddleware() as $middleware) {
|
2026-10-02 12:09:46 +02:00
|
|
|
if (\is_string($middleware) && str_contains($middleware, 'auth:')) {
|
2023-08-16 10:36:05 +02:00
|
|
|
$route = $logins[str_replace('auth:', '', $middleware)] ?? null;
|
|
|
|
|
if ($route) {
|
|
|
|
|
return $route;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-02 12:09:46 +02:00
|
|
|
|
2023-11-21 16:24:23 +01:00
|
|
|
return route('fo.login');
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
2023-08-16 10:36:05 +02:00
|
|
|
|
|
|
|
|
return null;
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
|
|
|
|
}
|