2020-12-01 17:02:10 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
2023-09-06 17:24:53 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-09-04 13:08:34 +02:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2020-12-01 17:02:10 +01:00
|
|
|
|
2021-03-14 10:45:42 +01:00
|
|
|
/**
|
2023-09-06 17:24:53 +02:00
|
|
|
* Updated for ApiV4.
|
2021-03-14 10:45:42 +01:00
|
|
|
*/
|
2020-12-01 17:02:10 +01:00
|
|
|
class Authenticate extends Middleware
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the path the user should be redirected to when they are not authenticated.
|
|
|
|
|
*
|
2023-09-06 17:24:53 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-12-01 17:02:10 +01:00
|
|
|
* @return string|null
|
2023-09-06 17:24:53 +02:00
|
|
|
*
|
2020-12-01 17:02:10 +01:00
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
protected function redirectTo(Request $request): ?string
|
2020-12-01 17:02:10 +01:00
|
|
|
{
|
2023-09-04 13:08:34 +02:00
|
|
|
if (!$request->expectsJson()) {
|
|
|
|
|
// * Notify must login
|
|
|
|
|
Session::flash('warning', trans('Veuillez vous connecter pour continuer'));
|
|
|
|
|
|
2020-12-01 17:02:10 +01:00
|
|
|
return route('login');
|
|
|
|
|
}
|
2023-09-04 13:08:34 +02:00
|
|
|
|
|
|
|
|
return null;
|
2020-12-01 17:02:10 +01:00
|
|
|
}
|
|
|
|
|
}
|