【发布时间】:2020-05-28 03:00:36
【问题描述】:
我正在尝试在我的应用中添加 facebook 登录。它成功地工作,但问题是每次我用 facebook 登录它都会改变 firestore 数据。这是我的代码
onLoginSuccess(res: FacebookLoginResponse) {
const credential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
this.fireAuth.auth.signInWithCredential(credential)
.then((response) => {
console.log(response);
this.fb.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', []).then(profile => {
this.userData = {email: profile['email'], first_name: profile['first_name'], picture: profile['picture_large']['data']['url'], username: profile['name']}
console.log(this.userData);
console.log(this.fireAuth.auth.currentUser.uid);
let userData = {
email: this.userData.email,
username: this.userData.username,
photo: this.userData.picture,
phone: '',
point : '0',
uID: this.fireAuth.auth.currentUser.uid
};
this.angularFirestore.collection('AppUsers').doc(this.fireAuth.auth.currentUser.uid).set(userData); //Here is the problem
this.router.navigate(["/select"]);
})
});
}
我需要检查this.fireAuth.auth.currentUser.uid 是否已经有可用的文档,所以它不会添加到数据库中。如果不可用,它将存储在数据库中。
所以我需要如何检查 docID 是否存在的方法?
【问题讨论】:
-
检查文档是否存在之前已经问过:stackoverflow.com/…。你有没有尝试过类似的东西?
标签: javascript angular ionic-framework google-cloud-firestore