I am trying to auto approve users who have a certain domain in their email who signup with Google Login (Social Auth Google) by creating an Event subscriber using the User Fields Event.
The code works but surprisingly the user is approved only after they try to login. Not sure if its a bug in the Social auth or in my code. Is there any other event that needs to be used or is there something missing in the code below.
public function onSocialAuthUserFieldEvent(UserFieldsEvent $event) {
$user = $event->getUserFields();
$user_email = $user['mail'];
// Checking if the user has email id as abcode.com and setting
// status to 1 If user has another email domain we do nothing and
// leave it to the admins.
if (preg_match('/.*@abcd\\.com$/i', $user_email) > 0) {
// Setting the user account status to be active by default.
$user['status'] = 1;
$event->setUserFields($user);
$this->loggerFactory->notice('Auto approved Abcd user with mail id: %user_email ', ['%user_email' => $user_email]);
}
Comments
Comment #2
gvsoLet me see if I understood what your issue is.
'Valid' users are not approved after registration with Google. They have to try to log in again in order for them to be considered approved. Is that correct?
You want them to be automatically logged in into your site after they register, but that's not the case. Right?
Comment #3
gvso