ldc-qrcollector-back/app/Http/Middleware/Authenticate.php

40 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2023-03-28 14:37:49 +00:00
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
2026-02-12 16:09:21 +01:00
use Illuminate\Http\Request;
2023-03-28 14:37:49 +00:00
use Illuminate\Support\Facades\Session;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
2026-02-12 16:09:21 +01:00
* @param \Illuminate\Http\Request $request
2023-03-28 14:37:49 +00:00
* @return string|null
*/
2026-02-12 16:09:21 +01:00
protected function redirectTo(Request $request)
2023-03-28 14:37:49 +00:00
{
$logins = [
// Dans tous les cas bo.login.
'frontend' => route('bo.login'),
2023-03-28 14:37:49 +00:00
'backend' => route('bo.login')
];
if (!$request->expectsJson()) {
// * Notify must login
Session::flash('warning', trans('Veuillez vous connecter pour continuer'));
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;
}
}
}
2024-04-24 16:19:02 +02:00
return route('bo.login');
2023-03-28 14:37:49 +00:00
}
abort(401);
}
}