Why after login user keeps both roles guest and user in yii2?

i'm using rbac in yii2 project. When i print

var_dump(\Yii::$app->authManager->getRolesByUser(Yii::$app->user->id));

I get an array with two elements: guest and user? Why "guest" role stays at authorized user? Is it normal behavior or I did something wrong?

1 answer

  • answered 2018-05-16 08:12 rob006

    This is expected. If you add some role to defaultRoles, it will be always available, regardless of authentication state. From $defaultRoles docs:

    A list of role names that are assigned to every user automatically without calling assign(). Note that these roles are applied to users, regardless of their state of authentication.