How could I limit that the user can only be logged in to the system at a time? I am using the authentication system that Laravel brings by default. In the event that you try to log in a second time, the previous one should be closed.
How could I limit that the user can only be logged in to the system at a time? I am using the authentication system that Laravel brings by default. In the event that you try to log in a second time, the previous one should be closed.
After having investigated I found for laravel 5.5 this
**Solution**
1. Copy
sendLoginResponse
file function:and paste it into the file
This will override the default function
sendLoginResponse
, (you should never do this directly on the file in the vendor folder, as performing a composer update will lose your changes).2. Update your database by adding a text type field to the users table called:
.
3 . Leave the function you copy in your LoginController
sendLoginResponse
like thisLaravel already has support for this.
Upon request I will repeat what the documentation clearly says. First update laravel to the latest version or later than 5.6 This is very simple you just have to update the composer.json on line 13 for this.
Then in your console execute the command
Once you update the project you should go to the midelwares kernel and uncomment this line.
Once you uncommented it you have to add the following line with the auth fakade (obviously where you login or where you require the session to be unique per user).
Obviously prior to this you have to have the user's password available. A very practical example would be in the normal login of Laravel. In the login constructor
And so in any other use case.
https://laravel.com/docs/5.6/authentication#invalidating-sessions-on-other-devices