firebase signInWithCredential return phone number with null when i sign in with social media like google or facebook
this is the sample of firebase response:
{"additionalUserInfo": {"isNewUser": true,"user": {"displayName":"i set it private","email":
"i set it private","phoneNumber":null,"photoURL":"i set it private"}}
i try this function with google and same for facebook and apple :
void googleSingIn() async {
emit(GoogleAuthLoadingState());
if (await checkConnectivity() == AppConstants.connectivityWifi ||
await checkConnectivity() == AppConstants.connectivitymobile) {
try {
// Trigger the authentication flow
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleSignInAccount =
await googleSignIn.signIn();
if (googleSignInAccount == null) {
return;
}
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleSignInAccount.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
// Once signed in, return the UserCredential
final userCredential =
await FirebaseAuth.instance.signInWithCredential(credential);
final googleUser = userCredential.user;
final additionalUserInfo = userCredential.additionalUserInfo;
dev.log("$userCredential");
if (additionalUserInfo!.isNewUser == false) {
login(
email: googleUser!.email!,
password: googleUser.uid,
method: AppConstants.googleMethod,
);
} else {
RouteGenerator.registerCubit.register(
google: googleUser!.email,
googlePassword: googleUser.uid,
firstName: additionalUserInfo.profile?["given_name"],
lastName: additionalUserInfo.profile?["family_name"],
image: googleUser.photoURL,
);
}
} catch (e) {
emit(GoogleAuthErrorState(error: e.toString()));
}
} else {
emit(LogInConnectivity(
connectivityMessage: StringsManager.connectionError));
}
}
3
Answers
As far as I know, firebase social media sign-in are different than phone number sign in. This is phone sign documentation for web. I didn’t test this myself but i think phone sign in is a different provider and if only user signs in with phone, then you can see phone provider and phone number in the user info.
Unless you’re signing in with a phone number, the phone number field is unlikely to be populated.
Social sign-in providers (for privacy reasons) don’t auto-expose a user’s phone number by default, so if you want to get this – you will have to explicit ask for it (by adding the relevant scope). For an example of this, see how i can retrieve gender and phone number and birthdate from signInWithGoogle flutter
According to the documentation for the phoneNumber property:
So you can expect this to be null unless the user signed in with phone number authentication.