39 lines
1.7 KiB
PHP
39 lines
1.7 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
use Illuminate\Http\Request;
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
web: __DIR__.'/../routes/web.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withMiddleware(function (Middleware $middleware) {
|
|
//
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions) {
|
|
$exceptions->render(function (HttpException $e, Request $request) {
|
|
if ($e->getStatusCode() === 419) {
|
|
|
|
if ($request->expectsJson()) {
|
|
return response()->json([
|
|
'message' => 'Your session has expired. Please refresh the page and try again.'
|
|
], 419);
|
|
}
|
|
|
|
// fallback('/login') ensures that if the session was completely lost,
|
|
// it defaults back to the login page instead of crashing or going to the root URL.
|
|
// return redirect()->back()->fallback('/login')
|
|
// ->withInput($request->except('password'))
|
|
// ->withErrors(['email' => 'Your session expired due to inactivity. Please try logging in again.']);
|
|
// The third parameter sets '/login' as the fallback if the Referer header is missing
|
|
return redirect()->back(302, [], '/login')
|
|
->withInput($request->except('password'))
|
|
->withErrors(['email' => 'Your session expired due to inactivity. Please try logging in again.']);
|
|
}
|
|
});
|
|
})->create(); |