mardi 7 juillet 2020

does google login in laravel socialite contain a user's phone number?

i implemented google login using socialite in laravel and soo am the example i used only contains the user's name, google_id, email and profile picture. is there a way to get the phone number from the google callback? or does it even contain the number?? Heres the function that handles the callback;

public function handleProviderCallback()
{
    try {
        $user = Socialite::driver('google')->user();
    } catch (\Exception $e) {
        return redirect('/login');
    }
    // check if they're an existing user
    $existingUser = User::where('email', $user->email)->first();
    if($existingUser){
        // log them in
        auth()->login($existingUser, true);
    } else {
        // create a new user
        $newUser                  = new User;
        $newUser->name            = $user->name;
        $newUser->email           = $user->email;
        $newUser->google_id       = $user->id;
        $newUser->avatar          = $user->avatar;
        $newUser->avatar_original = $user->avatar_original;
        $newUser->save();
        auth()->login($newUser, true);
    }
    return redirect()->to('/');
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire