I want to log out the user if the IP has changed.
I managed to make it by creating a field lastLoginIp
in the Users table, setting it in the onAuthenticationSuccess
, and then checking in the User::isEqualTo()
method:
if($user->getLastLoginIp() !== Utils::getIp()) {
return false;
}
The problem is that it broke impersonation, because of course the IP of the admin is different than the IP of the user.
How can this be implemented? (and the user must not get logged out if somebody impersonates him)