calling Yii::$app->user->identity->getAuthKey()

I have created a new folder in yii2 at same level with backend and frontend to handle rest api calls. This folder contains a module for apis. It has a models with a User.php model. Am not using the one in common folder as this model is special to this module. Inside it, I have a method called


    public function getAuthKey() {

        return $this->auth_key;

    }

. So when I to try to call this method in my user controller as


Yii::$app->user->identity->getAuthKey()

, it returns null. I don’t know why I think it might be trying to get the one from user class in common folder and not from the one in the module. Please help.

That’s normally. Let see in the common/config/main.php, you can see the user component config like bellow


'user' => [

    'identityClass' => 'common\models\User',

    'enableAutoLogin' => true,

],

And then you call


Yii::$app->user

.

It mean you call user component user registed in common config and one instance of


common\models\User

will be return. So that’s your problem

Then how can I use the one in my module.