Im trying to implement single device login, meaning that if a user is logged in another device and tries to log to a new device, than he will be logged out from the previous device,
for this end, after successful login i call the following method
Auth::logoutOtherDevices($request['password']);
while this works, after i log out and try to log in again, i get invalid credentials,
i tried to debug and see that Auth::validate($credentials)
returns false, and that Hash::check($credentials['password'], $user->password)
is also false
i know that internally the logoutOtherDevices
rehashes the password and also noticed that if i provide wrong password, it throws exception, but i dont understand what im doing incorrectly, if it matters my session driver is redis
2
Answers
Rather than re-hash the password, you can delete all the current sessions for the user, which effectively logs they out of every device.
The following code checks if the app is running in
production
and then deletes all the sessions for the user$user
:You might need to create a model called
Session
, and check thatSESSION_DRIVER
in the.env
file is set todatabase
. Also, check that you have a table calledsessions
in the database.For redis, I’m sure a similar approach would work. You would need to delete the user’s sessions from redis to log them out from every device.
Jetsream uses something like this. you can do the same.
logoutOtherDevices
: will rehash your password and send logout event for other devicesdeleteOtherSessionRecords
: deletes session data for other devices