@bervetuna I would suggest just creating a listener and hooking this into the auth Login event. Your direction with using logoutOtherDevices should work there.
Jetstream: Log out on other devices on log in
I'm working on an app and would like to prevent users to be logged in on multiple devices.
The documentation mentions this can be done by uncommenting the Illuminate\Session\Middleware\AuthenticateSession middleware in App\Http\Kernel and then use the logoutOtherDevices method provided by the Auth facade.
I tried so by adding the following code in the FortifyServiceProvider boot method:
Fortify::authenticateUsing(function (Request $request) { $user = User::where('email', $request->email)->first();
if ($user &&
Hash::check($request->password, $user->password)) {
Auth::logoutOtherDevices($request->password);
return $user;
}
});
I was hoping that calling the logoutOtherDevices method before returning the user would logout the user from other sessions. That is not the case.
What am I doing wrong here?
Thanks!
@Bervetuna I could be wrong but from what I remember, authed sessions I believe are based on an auth identifier that is based on your ip address. Try logging in from you phone - not on wifi. It should accomplish what you are trying. Do you really care if someone is logged in from 2 browsers on the same machine?
Has to be a different device - thus logoutOtherDevices
This actually may be able to exist on the same wifi or network. I can't remember what the identifier is. ...but honestly what was posted should be sufficient to do what you're ultimately wanting. Test this using two different devices on different networks. Building anything more complex than that seems highly unnecessary.
Please or to participate in this conversation.