[🐛] Google Social Sign returns user without email and emailVerified: false
Issue
I'm using the firebase social login, with the google provider. I followed all the required steps, in both libs (firebase and @react-native-google-signin/google-signin) and everything seemed to work fine. As part of the sign-in I need to verify the current user email that's returned from the login request.
However, a couple of days ago I started to get reports from users, that they can't log in. I found out that the function auth().signInWithCredential(googleCredential); returns the user object with "email": null, "emailVerified": false; but the additionalUserInfo object returns `{"profile":{ "email": [email protected], "email_verified": true }}.
All the relevant accounts that reported the issue have verified Gmail accounts.
code usage:
const { idToken } = await GoogleSignin.signIn({});;
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
const { user, additionalUserInfo } = await auth().signInWithCredential(googleCredential);
console.log({ user }); // {"user": {"displayName": "Yuval Padova", "email": null, "emailVerified": false}}
console.log({ additionalUserInfo }); // {"additionalUserInfo": {"isNewUser": false, "profile": { "email": "[email protected]", "email_verified": true }}}
Project Files
Javascript
Click To Expand
package.json:
"@react-native-firebase/app": "^14.11.1",
"@react-native-firebase/auth": "^14.11.1",
"@react-native-firebase/database": "^14.11.1",
"@react-native-google-signin/google-signin": "^8.0.0",
"react-native": "^0.69.0",
"react-native": "^0.69.0",
firebase.json for react-native-firebase v6:
# N/A
iOS
Click To Expand
ios/Podfile:
- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:
# N/A
AppDelegate.m:
// N/A
Android
Click To Expand
Have you converted to AndroidX?
- [ ] my application is an AndroidX application?
- [ ] I am using
android/gradle.settingsjetifier=truefor Android compatibility? - [ ] I am using the NPM package
jetifierfor react-native compatibility?
android/build.gradle:
// N/A
android/app/build.gradle:
// N/A
android/settings.gradle:
// N/A
MainApplication.java:
// N/A
AndroidManifest.xml:
<!-- N/A -->
Environment
Click To Expand
react-native info output:
System:
OS: macOS 12.5
CPU: (8) arm64 Apple M1 Pro
Memory: 111.58 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.0 - /var/folders/wk/nw8hp47d17n8s4mndjw__m980000gr/T/yarn--1663683478968-0.9373233747125695/node
Yarn: 1.22.18 - /var/folders/wk/nw8hp47d17n8s4mndjw__m980000gr/T/yarn--1663683478968-0.9373233747125695/yarn
npm: 8.5.5 - /usr/local/bin/npm
Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 30, 31, 32
Build Tools: 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0
System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: ^18.2.0 => 18.2.0
react-native: ^0.69.0 => 0.69.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
-
Platform that you're experiencing the issue on:
- [x] iOS
- [x] Android
- [ ] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
-
react-native-firebaseversion you're using that has this issue:-
e.g. 14.11.1
-
-
Firebasemodule(s) you're using that has the issue:-
e.g. Instance ID
-
-
Are you using
TypeScript?-
Y&4.4.4
-
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
It is unfortunate that this is reproduced on old versions, as there is the chance this behavior has already changed with current versions (v14 vs v15) - please make sure you can reproduce on current versions
Firebase has some interesting behavior with regard to emails and social logins. It treats things it thinks are "strongly verified" (historically, via google mail accounts) as authoritative and would put them in the user account directly if the user's first login was via a social method that was strongly verified.
It considered other sources weakly verified (I believe facebook fell in that bucket) and they were on additionalUserInfo as you mention.
It has a harder job when the account already exists and the user is combining accounts (say, they want to login via either facebook or google, or apple, or email or phone) to the same account. I found the behavior there to be variable as to what would show up in the user's direct email unless it was specifically the email authentication provider (it always goes in the user's email slot).
What does this all mean? In practice: when doing social login, use the additionalUserInfo bit every time (and copy it in to the user's main email slot if that's an important use case). That's a pragmatic solution that works.
If you want to really dig in to it, this is not react-native-firebase specific behavior and I/we won't have answers here unfortunately. This is behavior handled in the cloud and translated by the underlying SDKs. For questions like that you should head to stackoverflow and ask there with appropriate tags, as firebase offers fairly rapid user support on that platform.
If you learn something authoritative I'd be interested in seeing the link for it dropped here
I had the same issue, and I found that it is caused by Create multiple accounts for each identity provider in Firebase/Authentication/Settings.
Hello 👋, to help manage issues we automatically close stale issues.\n\nThis issue has been automatically marked as stale because it has not had activity for quite some time.\nHas this issue been fixed, or does it still require attention?\n\n> This issue will be closed in 15 days if no further activity occurs.\n\nThank you for your contributions.