I am trying to implement firebase authentication in react typescript app. I'm also using the method fetchSignInMethodsForEmail but I can't resolve the error.
The code is:
if(error.code === 'auth/account-exists-with-different-credential') {
var pendingCred = error.credential;
var existingEmail = error.email;
fire.auth.fetchSignInMethodsForEmail(existingEmail).then(methods => {
if(methods[0] === 'password') {
var password = window.prompt('Enter Password for Existing Email: ' + existingEmail) as string;
fire.auth.signInWithEmailAndPassword(existingEmail, password).then(fbUser => {
return fbUser.user.linkWithCredential(pendingCred);
}).then(fbUser => {
this.props.loginUserSuccess(fbUser);
});
return;
}
})
}
The error is on line 5 return statement when it executes the then method:
Argument of type '(providers: string[]) => Promise | undefined' is not assignable to parameter of type '(value: string[]) => UserCredential | PromiseLike'. Type 'Promise | undefined' is not assignable to type 'UserCredential | PromiseLike'. Type 'undefined' is not assignable to type 'UserCredential | PromiseLike'
Function containing the above code:
loginMicrosoft = () => {
this.props.loginUser();
var microsoftProvider = new firebase.auth.OAuthProvider("microsoft.com");
microsoftProvider.setCustomParameters({
prompt: 'select_account'
});
fire.auth
.signInWithPopup(microsoftProvider)
.then( msUser => {
this.props.loginUserSuccess(msUser);
})
.catch(error => {
if(error.code === 'auth/account-exists-with-different-credential') {
var pendingCred = error.credential;
var existingEmail = error.email;
fire.auth.fetchSignInMethodsForEmail(existingEmail).then(methods => {
if(methods[0] === 'password') {
var password = window.prompt('Enter Password for Existing Email: ' + existingEmail) as string;
fire.auth.signInWithEmailAndPassword(existingEmail, password).then(fbUser => {
return fbUser.user.linkWithCredential(pendingCred);
}).then(fbUser => {
this.props.loginUserSuccess(fbUser);
});
return;
}
})
}
});
}