'Getting "undefined" from error.email when trying to link multiple auth providers in firebase
I'm trying to link multiple auth providers to one account using firebase. The user is trying to create an account with the same address as the Google OAuth account which is already on firebase.
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(async result => {
if (result.additionalUserInfo.isNewUser) {
firebase
.database()
.ref('/users/' + result.user.uid)
.set({
email: email,
profile_picture: image,
first_name: firstName,
last_name: lastName,
created_at: Date.now()
})
.then(snapshot => console.log("do something"))
} else {
firebase
.database()
.ref('/users/' + result.user.uid)
.update({
last_logged_in: Date.now()
})
.then(snapshot => console.log("do something"))
}
})
.catch(error => {
if (error.code === 'auth/email-already-in-use' || error.code === 'auth/credential-already-in-use' || error.code === 'auth/account-exists-with-different-credential') {
const pendingCred = error.credential
const email = error.email
firebase
.auth()
.fetchSignInMethodsForEmail(email)
.then(methods => {
switch (methods[0]) {
case 'password':
// email and password logic
break;
case 'facebook.com':
// facebook logic
break;
default:
break;
}
})
return;
}
})
The problem is I'm getting the proper error message:
[Error: The email address is already in use by another account.]
and the proper error.code:
auth/email-already-in-use
but, pendingCred or error.email come back undefined.
Update
I took the advise and tried the following:
firebase.auth()
.EmailAuthProvider
.credential(email, password)
.then(result => console.log("result", result))
.catch(error => console.log(error))
I'm getting the error:
[TypeError: undefined is not an object (evaluating '_firebase.default.auth().EmailAuthProvider.credential')]
Solution 1:[1]
The email was in error.customData.email for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akshay K Nair |
