Yii2 login not working properly on remote server

200 views Asked by At

I have a login problem on the remote server. I followed the error and discovered that the user is logged in this returns true in the LoginForm and at this level, I have the user

Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0)

However, at the controller when the login action receives true and redirects to the profile page, the latter shows null for

var_dump(\Yii::$app->user->identity);

I tried using DbSession, but the table also has null for the user_id.

Can anyone please help me to solve this issue, I have been working on it for the past 3 days.

Here are some samples of my code

public function actionLogin() {
    $login = new LoginForm('app');

    if ($login->load(Yii::$app->request->post()) && $login->login()) {
        $this->redirect(['/profile']);
    }
    return $this->render('login', [
        'login' => $login,
    ]);
}

profile controller

public function actionIndex() {
        var_dump(\Yii::$app->user->identity); // here i get null
        die();
    $dashboard = new Dashboard();
    return $this->render('index', [
        'dashboard' => $dashboard,
    ]);
}

common main conf

    'session' =>
    [
        'class' => 'yii\web\DbSession',
    ],

frontend conf

    'user' => [
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
    ],
    'session' => [
        'name' => 'app-frontend',
    ],
0

There are 0 answers