Yii2:前端用户注销但后端保持登录状态

时间:2021-07-21 13:51:40

标签: php yii2 user-controls logout

我遇到了一个问题,当我从前端或后端注销时,另一个仍然登录。我一直在网上寻找解决方案,但没有找到类似的东西。我应该更改什么,以便当我从前端或后端注销时,另一个必须注销。

登录对两者都正常工作:

public function actionLogout()
{
    Yii::$app->user->logout();

    return $this->goHome();
}

1 个答案:

答案 0 :(得分:0)

请更新您的前端和后端 main.php 如下

'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-auth', 'httpOnly' => true],
    ],
    'session' => [
        // this is the name of the session cookie used for login on the frontend
        'name' => 'AuthSession',
    ],  

一旦 identityCookie 和会话相同,那么您就可以从前端和后端管理您的会话。

相关问题