I'm creating a login with email and pass (that works fine) plus the login with Google, the login works but neither in Firebase console nor in the code with 'account.email' can I see the email.
binding.btGoogle.setOnClickListener() {
val googleConfig: GoogleSignInOptions =
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id)).build()
val googleClient: GoogleSignInClient = GoogleSignIn.getClient(this, googleConfig)
googleClient.signOut()
startActivityForResult(googleClient.signInIntent, GOOGLE_SIGN_IN)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == GOOGLE_SIGN_IN) {
val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account: GoogleSignInAccount? = task.getResult(ApiException::class.java)
//here 'account.email' is already null
if (account != null) {
val credential: AuthCredential = GoogleAuthProvider.getCredential(
account.idToken,
null
)
FirebaseAuth.getInstance().signInWithCredential(credential).addOnCompleteListener() {
if (it.isSuccessful) {
showHome(account.email ?: "", ProviderType.GOOGLE)
} else {
showAlert()
}
}
}
} catch (e: ApiException) {
showAlert()
}
}
}
In debugging, I can see other attributes like displayName, givenName, idToken... but email is just null.
Solutions I tried:
Both with the option on and off from Firebase "Avoid creating multiple accounts with the same e-mail"
Using 'account.email' or 'getEmail()'
Something that bothers me:
I missed one word.
I had this:
val googleConfig: GoogleSignInOptions =
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.build()
And I needed this:
val googleConfig: GoogleSignInOptions =
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()