result.user.link не является функцией в угловой пожарной базе

1

Не удалось связать учетную запись facebook с существующей учетной записью Firebase. В настоящее время у меня есть учетная запись firebase, которую я создал с помощью учетных данных google. Теперь я хочу связать учетную запись facebook с этой уходящей учетной записью Firebase (оба имеют одинаковые скрипты), и я выполнил следующие шаги: https://firebase.google.com/docs/auth/web/facebook-login

Но, наконец, когда я вызываю метод "result.user.link(pendingCred).then((user) => {..}", чтобы связать учетную запись, я получаю следующую ошибку в консоли:

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)

Вот мой код

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 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);
                    });
                });
            });
        }
    });
}

Пожалуйста, дайте мне знать, если я ничего не пропущу. Спасибо!

Теги:
angular
firebase-authentication

1 ответ

3

Изменить на result.user.linkWithCredential(pendingCred).then( (user)... link устарела в пользу linkWithCredential начиная с версии 4.0.0.

  • 2
    Спасибо за ваше предложение. После долгих испытаний я получил этот firebase.auth (). CurrentUser.linkWithCredential (pendingCred) .then (...). Наконец-то это сработало ..

Ещё вопросы

Сообщество Overcoder
Наверх
Меню