【发布时间】:2020-01-19 22:16:31
【问题描述】:
我正在创建一种登录方法,该方法试图检查我当前的用户在验证他们的电子邮件地址后是否同意我的协议条款。我的功能如下:
SignIn(email, password) {
return this.afAuth.auth.signInWithEmailAndPassword(email, password)
.then(cred => {
this.ngZone.run(() => {
// Gets current signed in user.
this.afAuth.authState.subscribe(user => {
// Queries Details subcollection.
this.db.collection('users').doc(user.uid).collection('Details')
.get().toPromise().then(
doc => {
if (user.termsOfAgreement == false) {
this.router.navigate(['terms']);
} else {
this.router.navigate(['dashboard']);
}
})
})
});
}).catch((error) => {
window.alert(error.message)
})
}
我知道我正在获取 firebase 用户对象,并且它不包含我的特定子集合字段名称(即 user.termsOfAgreement)。但是我将如何访问这些?我正在尝试检查我的 termsOfAgreement 字段是真还是假。
注册时我的 Firestore 用户集合状态
User (Collection)
- lastLogin: timestamp
- name: string
- userId: string
Details (subcollection)
- termsOfAgreement: false
【问题讨论】:
标签: javascript firebase google-cloud-firestore angularfire