Laravel使用一个身份登录,然后使用后退按钮并使用另一个身份进行登录


Laravel login with one identity and use back button and login with another identity

我在原始设置中使用laravel 5.1。如果我使用user1的id登录,然后单击返回按钮进入登录页面,然后使用user2的id再次登录,我仍然会得到user1的内容。尝试在登录user2后刷新页面,但仍然可以获得user1的内容。

然后我覆盖功能

public function postLogin('Illuminate'Http'Request $request)

并添加到以下行:

Auth::logout();

有办法解决这个问题吗?

深入研究代码后,我发现问题出在中间件中。为了解决这个问题,对AuthController进行了两次修改:

首先,更改低于代码

public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}

public function __construct()
{
    $this->middleware('guest', ['except' => ['getLogout', 'postLogin']]);
}

第二,在函数postLogin()的开头添加'Auth::logout(),它就会工作!