問題描述
我運行了 php artisan make:auth 命令,然后我會一步步解釋我接下來要做什么來理解場景,
I run the php artisan make:auth command and I will explain step by step what I do after that to understand the scenario,
- 登錄新會話 (example.com/home)
- 打開一個新標簽并粘貼網址,即 example.com/home.
- 現在 2 個標簽頁在同一個會話中打開.
- 我從其中一個選項卡中單擊了注銷,它運行良好
- 然后,當我嘗試從另一個選項卡注銷時,它給我一個錯誤消息,提示419 頁面已過期",即使重新加載后它也無處可去.
問題是,這種情況可能會出現,我不想看到這個錯誤信息,點擊注銷后直接注銷,即使會話已過期.
The thing is, these kind of scenarios may arise, and I don't want to see this error message, just logout after clicking logout, even if the session is expired.
注意:這個問題不是因為沒有添加@csrf
推薦答案
嗯,這是一個明顯的信息,您可以嘗試為該頁面制作更好的布局,但仍然最好顯示它以便用戶知道發生了什么.如果您想以不同的方式處理它,您可以嘗試重定向到登錄頁面.
Well that's an obvious message you can maybe try to make a better layout for that page, but still it is good to show it so the user knows what happened. If you want to handle it differently you can try to redirect to the login page.
因此在您的 appExceptionsHandler.php
文件中的 render 方法中添加:
So in your appExceptionsHandler.php
file within the render method add this:
if ($exception instanceof IlluminateSessionTokenMismatchException) {
return redirect()->route('login');
}
這篇關于Laravel 5.8 顯示“419 頁面已過期"從已清除的會話中單擊注銷后的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!