Laravel - Prevent Multiple Login Of Same Credentials (logoutOtherDevices)
I have a Laravel web app where multiple users login but I need to prevent login if the user has already logged.
I know that Laravel has a method (logoutOtherDevices) to logout the user when a second user (same credentials) is login. But this method do not show any message when logout the user. I would like to inform the logged out user that another user has logged in.
@fylzero How should this be implemented with jetstream. I would like to disable the possibility of logging in on multiple devices.
I uncommented the Illuminate\Session\Middleware\AuthenticateSession middleware in App\Http\Kernel and added the following to the FortifyServiceProvider boot method:
@Snapey That's the functionality that I would like to implement, Snapey: as soon as a user logs in, I would like him to be logged out from other browser sessions.
How do you propose to 'flash' the logged out user. Their session will be closed. Nothing will happen until they send a request to the server. At this point, they are anonymous because they don't have a valid session, therefore you cannot give them a message.
Possible options
Prevent login whilst there is already an active session for the user. Display a message like 'already logged in elsewhere. Logout on other devices first'
Allow second login but do not logout the first session. Create a middleware that checks the number of sessions for the current user. If they have more than one session, and the request is coming from a session that was created earlier then redirect the user to a page that says 'session has been terminated by another login', and don't let them visit any other pages.