According to the documentation at https://firebase.google.com/docs/auth/web/google-signin#expandable-1, when error.code === 'auth/account-exists-with-different-credential', signInWithPopup() should return an error.email. However, in my specific case, I am encountering a different error:
FirebaseError: Firebase: Error (auth/account-exists-with-different-credential).
at createErrorInternal (assert.ts:122:1)
at _createError (assert.ts:83:1)
at _makeTaggedError (index.ts:258:1)
at _performFetchWithErrorHandling (index.ts:145:1)
at async _performSignInRequest (index.ts:188:1)
at async _signInWithCredential (credential.ts:37:1)
at async PopupOperation.onAuthEvent (abstract_popup_redirect_operation.ts:102:1)
In my case, error.email is showing up as undefined.
Here's the code snippet:
const handleSignIn = (provider: AuthProvider) =>{
signInWithPopup(auth, provider).then((result) => {
repeatAuth();
}).catch((error) => {
console.log(error);
if (error.code === 'auth/account-exists-with-different-credential') {
let pendingCred = error.credential;
let email = error.email;
console.log(error.email); // undefined
fetchSignInMethodsForEmail(auth, email).then( (methods) => {
console.log(methods);
if (methods[0] === 'password') {
var password = promptUserForPassword(); // TODO: implement promptUserForPassword.
signInWithEmailAndPassword(auth, email, password!).then((result) => {
return linkWithCredential(result.user, pendingCred);
}).then(() => {
repeatAuth();
});
return;
}
// TODO: implement getProviderForProviderId.
var provider = getProviderForProviderId(methods[0]);
signInWithPopup(auth, provider).then((result) => {
repeatAuth();
});
}).catch((error) => {
console.log(error);
});
}
});
Any assistance or guidance would be greatly appreciated. Thank you.