【发布时间】:2020-04-16 11:36:45
【问题描述】:
我有两个组件作为“用户”和“工人”登录。它们的数据在两个集合名称中分别为“用户”、“工人”。这是我的“用户登录”功能。
SignIn(email, password) {
this.value = this.afs.collection( 'users' , ref =>
ref.where('email', '==', email)
).valueChanges();
this.value.subscribe(data => {
this.datas = data;
console.log(this.datas )
return this.afAuth.auth.signInWithEmailAndPassword(email, password).then((result) => {
this.ngZone.run(() => {
this.router.navigate(['home']);
});
}).catch((error) => {
window.alert(error);
this.router.navigateByUrl('signinu');
})
});
}
所以在这个功能中,我可以使用“工人”收集数据登录。这意味着“工人”可以使用“用户登录”组件登录。那么如何解决这个问题呢?请帮帮我。
这是我的“工人登录”功能
SignIn(email, password) {
this.value = this.afs.collection('workers', ref =>
ref.where('email', '==', email)
).valueChanges();
this.value.subscribe(data => {
this.datas = data;
console.log(this.datas)
if (this.datas !== null) {
return this.afAuth.auth.signInWithEmailAndPassword(email, password).then((result) => {
this.ngZone.run(() => {
this.router.navigate(['/profile/' + this.datas[0].uid]);
});
}).catch((error) => {
window.alert(error);
this.router.navigateByUrl('signinu');
})
} else {
window.alert('Invalid user');
}
});
}
【问题讨论】:
-
我不清楚这里有什么问题。
-
我是工人。所以现在我以工人身份登录。当我点击“登录”按钮时,我应该进入我的“工人资料”页面。如果我登录时是用户,我应该转到“主页”。所以在这里它不起作用。即使他是“工人”或“用户”,也始终指向“主页”。
-
@DougStevenson clear?
标签: angularjs firebase google-cloud-firestore