Nicht in der Lage, facebook-Konto mit einem vorhandenen Firebase-Konto zu verknüpfen. Ich habe derzeit ein Firebase-Konto, das ich mit Google-Anmeldeinformationen erstellt habe. Jetzt mag ich ein Facebook-Konto mit diesem Austritt aus Feuerbasis-Konto verknüpfen (beide mit gleichen creadentials) und ich folgte die hier genannten Schritten: https://firebase.google.com/docs/auth/web/facebook-loginresult.user.link ist keine Funktion in eckigen firebase
Aber schließlich, wenn ich rufe Methode „result.user.link (pendingCred) .dann ((Benutzer) => {..}“Konto zu verknüpfen erhalte ich folgende Fehlermeldung in Konsole:
Uncaught TypeError: result.user.link is not a function
at auth.service.ts:188
at e.g (auth.js:23)
at Yb (auth.js:26)
at Ub (auth.js:26)
at z.webpackJsonp.../../../../@firebase/auth/dist/auth.js.h.Mb (auth.js:25)
at Cb (auth.js:19)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.run (zone.js:142)
at zone.js:873
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:425)
Hier ist mein Code
loginFacebook(): Promise<any> {
return this.afAuth.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider())
.then((result) => {
this.registerUserName = result.user.displayName;
this.authDbUsername = result.user.email.replace('.', '');
// this.setLoggedinUser(user)
})
.catch ((error) => {
if (error.code === 'auth/account-exists-with-different-credential') {
alert('You have already signed up with a different auth provider for that email.');
const pendingCred = error.credential;
// The provider account's email address.
const email = error.email;
// Get registered providers for this email.
firebase.auth().fetchProvidersForEmail(email).then((providers) => {
// Step 3.
// If the user has several providers,
// the first provider in the list will be the "recommended" provider to use.
if (providers[0] === 'password') {
// Asks the user his password.
// In real scenario, you should handle this asynchronously.
const password = this.promptUserForPassword(providers[0]); // TODO: implement promptUserForPassword.
firebase.auth().signInWithEmailAndPassword(email, password).then((user) => {
// Step 4a.
return user.link(pendingCred);
}).then(function(user) {
// Google account successfully linked to the existing Firebase user.
this.authState = user;
});
return;
}
// All the other cases are external providers.
// Construct provider object for that provider.
// TODO: implement getProviderForProviderId.
const provider = new firebase.auth.GoogleAuthProvider(); // this.getProviderForProviderId(providers[0]);
// At this point, you should let the user know that he already has an account
// but with a different provider, and let him validate the fact he wants to
// sign in with this provider.
// Sign in to provider. Note: browsers usually block popup triggered asynchronously,
// so in real scenario you should ask the user to click on a "continue" button
// that will trigger the signInWithPopup.
firebase.auth().signInWithPopup(provider).then((result) => {
// Remember that the user may have signed in with an account that has a different email
// address than the first one. This can happen as Firebase doesn't control the provider's
// sign in flow and the user is free to login using whichever account he owns.
// Step 4b.
// Link to Google credential.
// As we have access to the pending credential, we can directly call the link method.
const resultingUser = result.user;
result.user.link(pendingCred).then((user) => {
// Google account successfully linked to the existing Firebase user.
this.authState = user; // goToApp();
}).catch((errorInLinking) => {
console.log(errorInLinking);
});
});
});
}
});
}
Bitte lassen Sie mich wissen, wenn ich etwas fehle Danke!
Vielen Dank für Ihren Vorschlag. Nach vielen Versuchen habe ich diese Firebase.auth(). CurrentUser.linkWithCredential (pendingCred) .dann (...). Endlich hat es geklappt .. –