Jul 21, 2016
0
Level 1
Allow one login session per account
Hello,
Is there any way out of a box to implement such a system? What i mean is:
User A is logged on Account A User B logged onto Account A while User A was logged in, so user A got kicked from his login session
So far I've tried such an approach:
1.Created session_token field in users table
2.While user is logging in it stores new uniqid as session_token in database and stores it in session:
//Action when loging in
$user->session_token = uniqid('', true);
$user->save();
Session::put('session_token', $user->session_token);
//Middleware added in Kernel.php
if (!$this->auth->guest()){
if(Session::get('session_token') !== uniqid('', true)){
Auth::logout();
return redirect()->to('/auth/login');
} else{
return $next($request);
}
} else {
return $next($request);
}
But it's somehow malfunctioning, it randomly logouts user out of session and i have to log in like once a two minutes.
Any ideas how to improve it, or maybe is there any better approach?
Please or to participate in this conversation.