How to use authkey for cookie based login?

Hi! I would like to know what’s the right way to use authkey. I started working on a webapp based on the basic template of Yii2 and when I switched to a User model based on ActiveRecord the cookie based login did not longer work. The problem was I did not use the authkey field, so it was set to null. The cookie login was not working because authkey was not set. I found it out digging into the yii\web\User code:




protected function loginByCookie()

    {

        $value = Yii::$app->getRequest()->getCookies()->getValue($this->identityCookie['name']);

        if ($value === null) {

            return;

        }


        $data = json_decode($value, true);

        if (count($data) !== 3 || !isset($data[0], $data[1], $data[2])) {

            return;

        }

    ...

}



So I have two questions:

  • What’s the right way of using the cookie based login?

  • Is there any documentation about this?

Thanks!