Logout from every devices except the currently logged in one in Laravel 5.6 and above in 2 steps.
I have used laravel version 8 but you can also implement this in other versions of laravel.
1) Install Laravel Project. *Type the below code in your terminal.*
composer create-project --prefer-dist laravel/laravel Project121
2) Now Install Auth. To Install Auth type below command in your terminal.
composer require laravel/ui
php artisan ui vue --auth
npm install
npm run dev
3) Open kernel.php and add below code in web array Location of kernel.php app\Http\Kernel.php
'web' => [
\Illuminate\Session\Middleware\AuthenticateSession::class,
],
4) Open LoginController and add below code Location of LoginController app\Http\Controllers\Auth\LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function authenticated()
{
Auth::logoutOtherDevices(request('password'));
}
}
And that's all now try to login on 2 different browsers or 2 different devices
Did you find this article valuable?
Support Mrunali Khandekar by becoming a sponsor. Any amount is appreciated!