All Projects → protonemedia → Laravel Single Session

protonemedia / Laravel Single Session

Licence: mit
This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user.

Projects that are alternatives of or similar to Laravel Single Session

Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+142.11%)
Mutual labels:  laravel, laravel-5-package, authentication
Sudo Su
Laravel package to easily login as other users during development.
Stars: ✭ 554 (+483.16%)
Mutual labels:  laravel, laravel-5-package, authentication
Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (-16.84%)
Mutual labels:  laravel, laravel-5-package, authentication
Laravel Email Verification
Laravel package to handle user verification using an activation mail
Stars: ✭ 63 (-33.68%)
Mutual labels:  laravel, laravel-5-package
Flysystem Upyun
Laravel 又拍云文件存储,上传,删除。
Stars: ✭ 92 (-3.16%)
Mutual labels:  laravel, laravel-5-package
Laravel Paytm Wallet
Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.
Stars: ✭ 58 (-38.95%)
Mutual labels:  laravel, laravel-5-package
Laravel5.7 Vue Cli3 Boilerplate
Boilerplate / Starter kit. Laravel 5.7, Vue CLI 3 — Authentication with Email Verification. REST API.
Stars: ✭ 52 (-45.26%)
Mutual labels:  laravel, authentication
Laravel Api Health
Monitor first and third-party services and get notified when something goes wrong!
Stars: ✭ 65 (-31.58%)
Mutual labels:  laravel, laravel-5-package
Laravel Potion
laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.
Stars: ✭ 63 (-33.68%)
Mutual labels:  laravel, laravel-5-package
Watchable
Enable users to watch various models in your application.
Stars: ✭ 65 (-31.58%)
Mutual labels:  laravel, laravel-5-package
Laravel 5 Messenger
A Simple Laravel 5, 6, 7 & 8 Messenger with Pusher Capabilities
Stars: ✭ 75 (-21.05%)
Mutual labels:  laravel, laravel-5-package
Notifier
NO LIBRARIES socket per page bridge for your Laravel application. (CLIENT PART INCLUDED)
Stars: ✭ 57 (-40%)
Mutual labels:  laravel, laravel-5-package
Authen
🚦 User Authentication Identifiers for Laravel
Stars: ✭ 53 (-44.21%)
Mutual labels:  laravel, authentication
Laravel Editor Md
editor.md for Laravel , markdown editor for Laravel
Stars: ✭ 61 (-35.79%)
Mutual labels:  laravel, laravel-5-package
Laravel Wang Editor
wangEditor for Laravel
Stars: ✭ 52 (-45.26%)
Mutual labels:  laravel, laravel-5-package
Laravel Mongodb Passport
A package to get Laravel Passport working with MongoDB
Stars: ✭ 64 (-32.63%)
Mutual labels:  laravel, laravel-5-package
Laraupdater
Enable Laravel App Self-Update. Allow your Laravel Application to auto-update itself.
Stars: ✭ 75 (-21.05%)
Mutual labels:  laravel, laravel-5-package
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-16.84%)
Mutual labels:  laravel, laravel-5-package
Larrock Core
Core components for LarrockCMS
Stars: ✭ 46 (-51.58%)
Mutual labels:  laravel, laravel-5-package
Fluent Facebook
A laravel 5 package for reading and writing to facebook graph object with ease in laravelish syntax
Stars: ✭ 49 (-48.42%)
Mutual labels:  laravel, laravel-5-package

Laravel Single Session

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user. It assumes you use Laravel's Authentication features.

Requirements

Notes

Installation

You can install the package via composer:

composer require pbmedia/laravel-single-session

Publish the database migration and config file using the Artisan CLI tool.

php artisan vendor:publish --provider="Pbmedia\SingleSession\SingleSessionServiceProvider"

The database migration adds a session_id field to the users table. Run the migration to get started!

php artisan migrate

Now add the \Pbmedia\SingleSession\Middleware\VerifyUserSession middleware to the routes you want to protect.

Usage

Since Laravel 5.5 has support for Package Discovery, you don't have to add the Service Provider to your app.php config file.

In the single-session.php config file you can specify a destroy_event. This event will get fired once a previous session gets destroyed. You might want to use this to broadcast the event and handle the destroyed session in the user interface. The constructor of the event can take two parameters, The User model and ID of the destroyed session. Here is an example event:

<?php

namespace App\Events;

class UserSessionWasDestroyed
{
    public $user;
    public $sessionId;

    public function __construct($user, $sessionId)
    {
        $this->user = $user;
        $this->sessionId = $sessionId;
    }

    public function broadcastOn()
    {
        // return new PrivateChannel('channel-name');
    }

    public function broadcastWith()
    {
        return ['user_id' => $this->user->id];
    }
}

When using Laravel Passport it automatically prunes and revokes tokens from the database as well. This can be disabled by setting the prune_and_revoke_tokens option to false in the config file.

If you're using Laravel Passport's CreateFreshApiToken middleware, add the Pbmedia\SingleSession\Middleware\BindSessionToFreshApiToken middleware before the CreateFreshApiToken and add the VerifyUserSessionInApiToken middleware to the auth:api group:

$router->get('/', '[email protected]')->middleware([
    'web', 'auth', BindSessionToFreshApiToken::class, CreateFreshApiToken::class
]);

$router->get('/api', '[email protected]')->middleware([
    'api', 'auth:api', VerifyUserSessionInApiToken::class
]);

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].