Login expires instantly

Hi!

I have a Yii2 Basic setup that is experiencing problems with login. In siteController there is a action called login that tests authentication as follows.


$model = new LoginForm();

if ($model->load(Yii::$app->request->post() && $model->login())

{

    return $this->goHome();

}

else

{

    $this->render('login', ['model'=>$model]);

}



Basically the syntax here is unchanged from the example code set up with Yii basic webapp. I have made modifications in LoginForm and User model so it corresponds with my DB (and also finds the user in an Active Directory using LDAP). All this seems to work fine, the IF-statement above returns true and Yii::$app->user->isGuest is set to false. The user is thuss logged in.

After login the goHome() method redirects the user to the web root (www.domain.com) which should load actionIndex in siteController. In config/web.php defaultRoute is set to site.

But when the user is redirected the login expires and the user is logged out and returned to the login form. I can not understand what I have done wrong. Since the login works why does it expire expediently? It does not seem to matter what route I redirect the user to, the credentials are lost.

I´m not sure what code to attach to this message since the LoginForm and user models seems to work fine. Can there be a problem storing the session? Any clue to where to continue looking?

If I in beforeAction() in siteController output Yii::$app->user->isGuest I get false after login. So as far as I understand the problem occurs somewhere between the redirect goHome() and loading of the requested routes beforeAction(). Why oh why?

Should authKey or accessToken always update when a user login? In my DB authkey seems to stay untouched and accessToken is empty. In my Account model I have added a beforeSave() that generates a new randomstring to authkey, but this is not performed on login…?

Yii::$app->user->login() gets a static array with user info as first parameter and 1800 seconds as TTL.

enableAutoLogin is set to true.

I would love to get some help figuring this out. Thanks!

Oh sigh… never mind. After hours of debugging i realized that Yii::$app->user->id was null. Sorry to waste space!