Block concurrent login in Laravel - jetstream

Viewed 695

I build this laravel app with jetsream and it is working like a charm. (I am not a developer, i just watch youtube videos and try to build what i want)

I want to prevent concurrent login from same account. I saw what i believe is the solution here: php laravel preventing multiple logins of a user from different devices/browser tabs at a given time. But i am not sure how to implement it.

For starters, the solution on the above link says to check and make sure that the following code is present in "app/Http/Kernel.php"

Illuminate\Session\Middleware\AuthenticateSession

I checked my Kernel.php file and found this line.

\Laravel\Jetstream\Http\Middleware\AuthenticateSession

Is this the line i need to have? Is it different because i use jetstream?

Then the solution said to use the code as follow:

 use Illuminate\Support\Facades\Auth;
 Auth::logoutOtherDevices($password);

Where do i use it? Where should i paste this code?

Note: i have found several articles on how to achieve what i want but they are too advance for me.

I have been stuck on this for the past 2 hours. Can anyone help me sort this one out.

Regards

1 Answers

Yes, in your kernel.php file you found

\Laravel\Jetstream\Http\Middleware\AuthenticateSession this is because 

you are using jetstream so here you'll see web middleware group that you need to un-comment

'web' = 
[\Laravel\Jetstream\Http\Middleware\AuthenticateSession::class, ]
and then 
protected function authenticated(Request $request)
{$password = $request->password ;         
Auth::logoutOtherDevices($password);}

If this won't help you then you need to write customized code in your

LoginController.php to prevent multiple logins.

Related