I am using angular for front end and for backend I am using laravel. For API I used the official documents for api token : https://laravel.com/docs/6.x/api-authentication. My current version is laravel 8 but this also works.
My problem is: this token only support single session, if I logged in with same credentials on another device or browser the old one is logged out. Please help me where am I doing wrong.
config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => true,
],
],
api/LoginController
$token = \Illuminate\Support\Str::random(60);
$request->user()->forceFill([
'api_token' => hash('sha256', $token),
])->save();
in all other controller
public function __construct()
{
$this->middleware('auth:api');
}