Skip to content

A package to manage and logout your active session on other devices

License

Notifications You must be signed in to change notification settings

SignatureTech/laravel-session-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel

LaravelSessionLog : Manage and logout your active session on other devices


Table of contents

Introduction

LaravelSessionLog is a Laravel package, designed Manage and logout your active session on other devices.

Todo

  • Create Session for login
  • List of Active Sessions
  • Logout Specific Device Session
  • Logout Other Devices Session

Features

  • Logged Session Log
  • Show Logged in devices
  • Logout Specific Device Session
  • Logout Other Devices Session

Installation & Configuration

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

Methods you can use

  • 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);

License

  • Written and copyrighted ©2022 by Prem Chand Saini ([email protected])
  • ResponseBuilder is open-sourced software licensed under the MIT license

About

A package to manage and logout your active session on other devices

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages