Laravel 5.8显示"419页已过期"从已经清除的会话中单击注销后 [英] Laravel 5.8 showing "419 Page Expired" after clicking logout from an already cleared session

查看:147
本文介绍了Laravel 5.8显示"419页已过期"从已经清除的会话中单击注销后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行 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)
  • 打开一个新选项卡并粘贴URL,即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.

因此在render方法的app\Exceptions\Handler.php文件中添加以下内容:

So in your app\Exceptions\Handler.php file within the render method add this:

if ($exception instanceof \Illuminate\Session\TokenMismatchException) {
    return redirect()->route('login');
}

这篇关于Laravel 5.8显示"419页已过期"从已经清除的会话中单击注销后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆