LaravelSessionLog is a Laravel package, designed Manage and logout your active session on other devices.
- Create Session for login
- List of Active Sessions
- Logout Specific Device Session
- Logout Other Devices Session
- Logged Session Log
- Show Logged in devices
- Logout Specific Device Session
- Logout Other Devices Session
You can install this package via composer using:
composer require signaturetech/laravel-session-log
Now instruct the our custom model via the usePersonalAccessTokenModel method provided by Sanctum. Typically, you should call this method in the boot method of one of your application's service providers
Please below code to AppServiceProvider in boot method
use SignatureTech\LaravelSessionLog\Models\PersonalAccessToken;
use Laravel\Sanctum\Sanctum;
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
}
Now add the use SignatureTech\LaravelSessionLog\SessionLog trait to your model.
use Laravel\Sanctum\HasApiTokens;
use SignatureTech\LaravelSessionLog\SessionLog;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, SessionLog;
}
Note: Please do't forgot to add Laravel\Sanctum\HasApiTokens Sanctum default trait to your model
To issue a token, you may use the createLoginToken method:
$token = $user->createLoginToken('TokenName')->plainTextToken;
Note: Please use createLoginToken function to generate access token insted of createToken of Santum
- To Get All Active Sessions
$user = auth()->user();
$user->sessions();
- To Logout Other Devices Session
$user = auth()->user();
$user->logoutOtherDevices();
- To Logout Specific Device Session
$user = auth()->user();
$user->logoutDevice($id);
- Written and copyrighted ©2022 by Prem Chand Saini (prem@signaturetech.in)
- ResponseBuilder is open-sourced software licensed under the MIT license