firebase facebook auth获取用户数据

时间:2017-12-16 11:45:37

标签: firebase ionic-framework firebase-realtime-database firebase-authentication

我使用firebase auth系统在我的离子应用上登录facebook。

我尝试获取配置文件数据并在用户使用数据库登录后将其保存到数据库中。您可以使用以下代码检查我该怎么做。

用户可以成功登录但无法将数据设置到数据库中。 我怎么解决这个问题?

loginWithFacebook() {

this.facebook.login(['email']).then((response) => {
  let credintial = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
  firebase.auth().signInWithCredential(credintial).then(info => {
    this.userEmail = info['email'];
    this.userName = info['displayName'];
    this.userUid = info['uid'];
  });
});

this.afDatabase.database.ref(`dump/${this.userUid}`).set({
  username: this.userName,
  email: this.userEmail,
  uid: this.userUid,
  wallet: 0
}).then(data => {
  this.navCtrl.setRoot(TabsPage);
});

}

1 个答案:

答案 0 :(得分:0)

应该知道您正在使用异步功能,并且应该在成功登录后将记录插入数据库。

loginWithFacebook() {

    this.facebook.login(['email']).then((response) => {
        let credintial = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
        firebase.auth().signInWithCredential(credintial).then(info => {
            this.userEmail = info['email'];
            this.userName = info['displayName'];
            this.userUid = info['uid'];
            this.afDatabase.database.ref(`dump/${this.userUid}`).set({
                username: this.userName,
                email: this.userEmail,
                uid: this.userUid,
                wallet: 0
            }).then(data => {
                this.navCtrl.setRoot(TabsPage);
            });
        });
    });

}