title: Yii::$app->user->isGuest always true on main.php after login
body: <p>I want to implement user login into yii2 basic app.everything works properly except, when I tries to access <code>Yii::$app-&gt;user-&gt;isGuest</code> on layout main page. it always returns true. whats going wrong here?, please help me</p>
  
  <pre><code> public function actionLogin()
      {
          if (!Yii::$app-&gt;user-&gt;isGuest) {
              return $this-&gt;goHome();
          }
  
          $model = new LoginForm();
  
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;login()) { 
              Yii::$app-&gt;user-&gt;isGuest;  // i m getting this as false, which is correct, but after goBack(), I m getting it as true
              return $this-&gt;goBack();
          }
          return $this-&gt;render('login', [
              'model' =&gt; $model,
          ]);
      }
  </code></pre>
  
  <p><strong>Login Mehod from LoginForm.php</strong></p>
  
  <pre><code> public function login()
      {
          if ($this-&gt;validate()) { 
              return Yii::$app-&gt;user-&gt;login($this-&gt;getUser(), $this-&gt;rememberMe ? 3600*24*30 : 0);
          }
          return false;
      }
  </code></pre>
  
  <p>Note : I am using custom theme, which rests outside the <code>web</code> folder and inside <code>project/themes/</code> directory</p>
  
  <p>** User Model is as follows**</p>
  
  <pre><code>&lt;?php
  
  namespace app\models;
  
  use Yii;
  use yii\behaviors\TimestampBehavior;
  use yii\db\ActiveRecord;
  use yii\web\IdentityInterface;
  use yii\web\NotFoundHttpException;
  
  class User extends ActiveRecord implements IdentityInterface {
  
      private $id;
      private $authKey;
  
      const STATUS_DELETED = '0';
      const STATUS_ACTIVE = '10';
  
      public static function tableName() {
          return '{{%user}}';
      }
  
      /**
       * @inheritdoc
       */
      public function behaviors() {
          return [
              TimestampBehavior::className(),
          ];
      }
  
      /**
       * @inheritdoc
       */
      public function getId() {
          return $this-&gt;id;
      }
  
      /**
       * @inheritdoc
       */
      public function getAuthKey() {
          return $this-&gt;authKey;
      }
  
      /**
       * @inheritdoc
       */
      public function validateAuthKey($authKey) {
          return $this-&gt;authKey === $authKey;
      }
  
      /**
       * Validates password
       *
       * @param string $password password to validate
       * @return boolean if password provided is valid for current user
       */
  
      public function validatePassword($password) {
          return Yii::$app-&gt;security-&gt;validatePassword($password, $this-&gt;password_hash);
      }
  
  
      public static function findByEmail($email) {
          $user_type = ['U'];
          return static::find()
                          -&gt;andWhere('email = :email', [':email' =&gt; $email])
                          -&gt;andFilterWhere(['in', 'user_type', $user_type])
                          -&gt;one();
      }
  
      public static function findIdentity($id) {
          $user = static::find()-&gt;where(['id' =&gt; $id, 'status' =&gt; self::STATUS_ACTIVE,])-&gt;one();
          if (empty($user-&gt;id)) {
              \Yii::$app-&gt;session-&gt;destroy();
          }
          return $user;
      }
  
      public static function findIdentityByAccessToken($token, $type = null) {
  
          $user = static::find()
                  -&gt;where([
                      'access_token' =&gt; $token,
                      'status' =&gt; self::STATUS_ACTIVE,
                  ])
                  -&gt;one();
          if (!empty($user)) {
              return $user;
          } else {
              throw new NotFoundHttpException('Invalid access token.');
          }
      }
  
  }
  </code></pre>