0

내 ionic 앱에서 facebook으로 로그인 할 때 firebase 인증 시스템을 사용하고 있습니다.firebase facebook auth 사용자 데이터 가져 오기

프로필 데이터를 가져 와서 데이터베이스에 사용자 로그인 한 후 데이터베이스에 저장하려고합니다. 다음 코드를 사용하여 어떻게 할 수 있는지 확인할 수 있습니다.

사용자는 성공적으로 로그인 할 수 있지만 데이터베이스에 데이터를 설정할 수 없습니다. 어떻게 해결할 수 있습니까?

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

} 

답변

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

}