php - laravel 8 +惯性js中的会话超时
问题描述
我正在使用 laravel 8 和惯性 js,我在 .env 文件中将 session_timeout 设置为 10 分钟。
问题是在我提交表单 10 分钟不活动后,我得到一个模型说 419 | 页已过期。如果我尝试访问其他页面,它就像没有超时会话一样工作
这是我的 .env 的代码
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=1
session.php 中的代码
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => true,
如何在 10 分钟不活动后将用户重定向到登录页面?
我的 handler.php 文件
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
//
}
}
解决方案
转到您的App\Exceptions\Handler文件,在 render 方法中您可以采取一些行动,如下所示:
public function render($request, Throwable $e)
{
$response = parent::render($request, $e);
if (!app()->environment('local') && $response->status() == 419){
//Delete the session by force
$request->session()->flush();
//Redirects to you login page, asuming this is your component's route
return Inertia::render('Auth/Login')
]);
/* Handling other exceptions' logic */
}
推荐阅读
- spring - Spring - 是否可以将外部配置项目不作为正在运行的服务,而是作为依赖项?
- java - 将字节数组转换为 Spark 列
- testing - 故事书和冒烟测试:有没有办法自动验证故事书中的所有故事?
- html - 带骨架的快速 LCP
- delphi - FireDAC 的 GetTableNames() 方法存在问题
- javascript - 如何编写将类组件作为功能组件返回的 React 组件?
- git - Github 网站提交作者用户名与 git log 中显示的用户名不同
- sql - 如何选择与其他属性无关的所有属性
- reactjs - 使用 react 和 next.js 导入 geojson
- java - Jersey 3.0.1 - 无法从 FormDataBodyPart 获取 MediaType