WordPress Google Signup Api

  google-oauth, php, wordpress

I want to create a custom google signup and sign in on WordPress using google API, what I want to do is get user information from google API, send it to the backend then it checks if user email exists it gets user info by get_user_by() function, if it does then it gets username and password from there and logs the user in through it, but the problem is the password returned is encrypted, so what is the possible solution to this? Is there any way to sign in as a user without the need for a password?

My Code:
if(isset($_POST['check'])){

       $username = sanitize_text_field( $_POST["fname"] );
       $email = sanitize_text_field($_POST["email"] );


if(email_exists($email)){
    $user = get_user_by( 'email', $email );
    $username = $user->user_login;
    $user_pass = $user->user_pass;
    
    
  $login_array = array();
  $login_array['user_login'] = $username;
  $login_array['user_password'] = $user_pass;
  
  
   $verify_user =  wp_signon( $login_array , true );
}

}

What i have tried:

if(email_exists($email)){
    $user = get_user_by( 'email', $email );

     clean_user_cache($user->ID);
     wp_clear_auth_cookie();
     wp_set_current_user($user->ID);
     wp_set_auth_cookie($user->ID, true, false);
     update_user_caches($user);
    
    
}

}

Source: Ask PHP

LEAVE A COMMENT