[英]Session timeout in laravel 8 + inertia js
我正在使用 laravel 8 和慣性 js,我將 session_timeout 設置為 10 分鍾 in.env 文件。
問題是在我提交表單后 10 分鍾不活動后,我得到一個 model 說 419 | 頁已過期。 如果我嘗試訪問其他頁面,它就像沒有超時 session
這是 my.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()
{
//
}
}
Go 到你的App\Exceptions\Handler文件,在渲染方法中你可以采取一些行動,像這樣:
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 */
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.