Reputation: 143
I am using Yii2, I want to user logout automatically and redirect to login page, after fixed idle seconds.
I already tried
'components' => [
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'authTimeout' => 60,
]
],
What should I do ?
Upvotes: 2
Views: 2899
Reputation: 3696
Don't set enableAutoLogin
to true
. Use the following configuration:
...
'user' => [
'identityClass' => 'backend\models\Users',
'enableSession' => true,
'authTimeout' => 300,
],
....
// below is documentation from source code for authTimeout
/**
* @var integer the number of seconds in which the user will be logged out automatically if he
* remains inactive. If this property is not set, the user will be logged out after
* the current session expires (c.f. [[Session::timeout]]).
* Note that this will not work if [[enableAutoLogin]] is true.
*/
Upvotes: 0
Reputation: 1721
You can set up JavaScript function to run every minute or so that makes ajax call and check if session for current user is expired. Then you can redirect with JavaScript with:
window.location("example.com/login");
Upvotes: 1
Reputation: 417
Did you have a 'loginUrl' property for your 'user'? See http://www.yiiframework.com/doc-2.0/yii-web-user.html
'user' =>[ 'loginUrl'=>['site/login']]
Does your Controller have rules for the actions that required authenticated users? See http://www.yiiframework.com/doc-2.0/guide-security-authorization.html
Upvotes: 0