Home > other >  is there a way to exclude displayName on GoogleSignIn
is there a way to exclude displayName on GoogleSignIn

Time:01-29

I don't want to retrieve the user name or profile photo that the user has on their Google Account.

export async function signUpGoogle() {
try {
    const result = await Google.logInAsync({
        androidClientId: GOOGLE_ANDROID_CLIENT_ID,
        iosClientId: GOOGLE_IOS_CLIENT_ID,
        scopes: ["email"],
    });

    //console.log(result);

    if (result.type === "success") {
        const credential = GoogleAuthProvider.credential(result.idToken);

        signInWithCredential(auth, credential).catch((error) => {
            console.log(error);
        });
    } else {
        console.log("cancelled");
    }
} catch (e) {
    return { error: true };
}}

The code I use for GoogleSignIn is above.

versions:

"expo": "~44.0.0",
"expo-google-app-auth": "~8.3.0",
"firebase": "^9.1.3",
"@react-native-firebase/auth": "^12.9.3",

CodePudding user response:

This should help

    const { user } = await auth.signInWithCredential(credential);
    const user = {
      photoURL: user.photoURL,
      displayName: user.displayName ?? 'User',
      uid: user.uid,
      email: user.email,
    };

CodePudding user response:

When you sign in with Google, the result that you get contains all that information, the UID, the display name, the profile picture URL. There is no way to exclude those fields. If you don't want to use them, then simply ignore them.

However, if don't want to get user details, then you should consider implementing Firebase Anonymous Authentication. In this way, you'll only have a UID, that can be only used to differentiate users. That's it.

  •  Tags:  
  • Related