Manage a User's Browser Sessions in Laravel
Published on by Paul Redmond
The Browser Sessions Laravel package by Chris Mellor enables users to manage and monitor their active browser sessions. Using this package, you can see user sessions that are active on other devices and provides options to terminate unrecognized or all sessions, enhancing account security:
use Cjmellor\BrowserSessions\Facades\BrowserSessions; // Retrieve a user's Current SessionsBrowserSessions::sessions();/*[ { "device": { "browser": "Safari", "desktop": true, "mobile": false, "platform": "OS X" }, "ip_address": "127.0.0.1", "is_current_device": true, "last_active": "1 second ago" }]*/
You can even log the user out of all other browser sessions besides their current session with:
BrowserSessions::logoutOtherBrowserSessions();
Lastly, you can get the user's last activity with this method:
BrowserSessions::getUserLastActivity();// orBrowserSessions::getUserLastActivity(human: true);
To get started with this package, you can find all the installation details on Github at cjmellor/browser-sessions