• This repository has been archived on 04/Mar/2020
  • Stars
    star
    101
  • Rank 326,268 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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('/', 'HomeController@show')->middleware([
    'web', 'auth', BindSessionToFreshApiToken::class, CreateFreshApiToken::class
]);

$router->get('/api', 'ApiController@index')->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.

More Repositories

1

laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
PHP
1,511
star
2

laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
PHP
1,382
star
3

laravel-cross-eloquent-search

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
PHP
990
star
4

laravel-form-components

A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4/5. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
PHP
807
star
5

inertiajs-tables-laravel-query-builder

Inertia.js Tables for Laravel Query Builder
PHP
425
star
6

eddy-server-management

Open-Source Solution for Server Provisioning and Zero-Downtime PHP Deployment
PHP
423
star
7

laravel-verify-new-email

This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
PHP
384
star
8

laravel-analytics-event-tracking

Laravel package to easily send events to Google Analytics
PHP
243
star
9

laravel-paddle

Paddle.com API integration for Laravel with support for webhooks/events
PHP
195
star
10

laravel-mixins

A collection of Laravel goodies.
PHP
135
star
11

laravel-task-runner

A package to write Shell scripts like Blade Components and run them locally or on a remote server
PHP
116
star
12

laravel-eloquent-scope-as-select

Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
PHP
102
star
13

laravel-xss-protection

Laravel XSS Protection Middleware
PHP
99
star
14

laravel-guidelines

Not necessarily coding standards (naming conventions, avoid else, etc.), but more like 'app'-guidelines - things you don't want to forget.
PHP
91
star
15

laravel-api-health

Monitor first and third-party services and get notified when something goes wrong!
PHP
87
star
16

form-components-pro

A set of Vue 3 components to rapidly build forms with Tailwind CSS 3. It supports validation, model binding, integrates with Autosize/Choices.js/Flatpickr, includes default vendor styling and is fully customizable! Even better in conjunction with Laravel Jetstream + Inertia.js.
JavaScript
82
star
17

laravel-webdav

WebDAV Serivce Provider for Laravel
PHP
59
star
18

laravel-blade-on-demand

Compile Blade templates in memory
PHP
50
star
19

inertia-vue-modal-poc

Proof of Concept: Load any route into a modal with Inertia.js
Vue
49
star
20

laravel-splade-core

A package to use Vue 3's Composition API in Laravel Blade components.
PHP
42
star
21

laravel-eloquent-where-not

This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
PHP
27
star
22

laravel-content

You provide the WYSIWYG editor, Media uploader, etc., and the package handles the validation, multi-language, storage, caching, sanitizing, etc.
PHP
23
star
23

inertiajs-events-laravel-dusk

Inertia.js Events for Laravel Dusk
PHP
22
star
24

laravel-dusk-fakes

Persistent Fakes for Laravel Dusk
PHP
17
star
25

laravel-minio-testing-tools

This package provides a trait to run your tests against a MinIO S3 server.
PHP
11
star
26

splade.dev

Source code for https://splade.dev
PHP
8
star
27

laravel-splade-docs

7
star
28

laravel-viewi

[WIP] Viewi for Laravel proof-of-concept: Build full-stack and completely reactive user interfaces with PHP.
PHP
5
star
29

eddy-backup-cli

Backup CLI for Eddy Server Management
PHP
3
star
30

form-components-pro-docs

A set of Vue components to rapidly build forms with Tailwind CSS v2.0. It supports validation, model binding, includes default vendor styling and is fully customizable!
JavaScript
3
star
31

laravel-tracer

[WIP] Trace authenticated users
PHP
2
star
32

eddy-filesystem-cli

PHP
1
star
33

laravel-ffmpeg-demo-app

A demo app to show all the cool things you can do with Laravel FFmpeg
1
star
34

php-apple-mapkit-token

Create a MapKit JS Token with PHP
1
star
35

laravel-browser-kit-macro

A macro to use the Laravel 5.3 testing layer inside your Laravel >5.3 tests
PHP
1
star
36

laravel-splade-plugin-skeleton

PHP
1
star