ldc-gen-game-web/app/Http/Middleware/Authenticate.php

40 lines
1.1 KiB
PHP
Raw Normal View History

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;
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
{
$logins = [
2026-10-02 12:09:46 +02:00
'backend' => route('bo.login'),
];
2026-10-02 12:09:46 +02:00
if (! $request->expectsJson()) {
// * 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:')) {
$route = $logins[str_replace('auth:', '', $middleware)] ?? null;
if ($route) {
return $route;
}
}
}
2026-10-02 12:09:46 +02:00
return route('fo.login');
2020-10-21 15:26:21 +02:00
}
return null;
2020-10-21 15:26:21 +02:00
}
}