使用this.afauth.auth.signinwithcredential时,我的Ionic应用程序一切正常。我可以使用google身份验证登录,用户配置文件被推送到firebase。但是,我在控制台中得到一个错误,即不推荐使用SignInWithCredential并使用SignInRetrieveDataWithCredential。问题是signandretrievedatawithcredential不提供任何用户数据(uid、用户电子邮件、displayname)…都为空。
那我该怎么办?控制台错误是说,即使signnWithCredential正常工作,也不要使用它。signandretrievedatawithcredential为用户返回空值。

  async googleLogin(): Promise<void> {
    try {

      const gplusUser = await this.gplus.login({
        'webClientId': environment.googleWebClientId,
        'offline': true,
        'scopes': 'profile email'
      });
      return await this.afAuth.auth.signInWithCredential(
        firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken)
      ).then((credential) => {
        console.log('creds', credential);
        this.updateUserData(credential);
      });
    } catch (err) {
      console.log(err);
    }
  }

      private updateUserData(user) {
    const userRef: firebase.firestore.DocumentReference = firebase.firestore().doc(`users/${user.uid}`);

    const data: User = {
      uid: user.uid,
      email: user.email,
      displayName: user.displayName,
    };
    console.log('user data', data);
    return userRef.set(data);
  }

最佳答案

如果我正确理解您的问题,我认为您的问题来自于两个方法返回不同的对象:
如前所述,signInWithCredential()返回一个here对象,
虽然
如前所述,User返回一个signInAndRetrieveDataWithCredential()对象,其中包含一个UserCredential对象。
所以你应该修改你的代码如下

  ....
  return await this.afAuth.auth.signInAndRetrieveDataWithCredential(
    firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken)
  ).then((credential) => {
    console.log('creds', credential.user);
    this.updateUserData(credential.user);
  });

09-12 21:25