在后端的用户架构中,我们在用户模型中具有isVerified。我们将Mongoose与Node.js结合使用。我们尝试检查isVerified是否为false,然后它应该导航到验证路线,但似乎它导航到结果为true时应该到达的路线。在数据库中时,它是错误的。这是代码:
applicationContext.xml
为什么从模型中不检查isVerified是true还是false?
答案 0 :(得分:0)
如果http请求成功,如果http请求不成功,那么您的代码将发送给人员路由,然后它检查isVerfied是否为false,然后验证路由。
如果您的isVerify字段来自db,则显示转到成功函数。
答案 1 :(得分:0)
您的代码中有几个问题
// never Called!
getUserById(user) {
this.usersService.GetUserById(user._id).subscribe(
data => {
this.user = data.result;
this.isVerified = data.result.isVerified;
},
);
}
signinUser() {
this.authService.loginUser(this.SigninForm.value).subscribe(
data => {
// might also return in case the loginUser fails (and it still returns data) -> try to output the data to see what is happening in this case
this.tokenService.SetToken(data.token);
this.SigninForm.reset();
setTimeout(() => {
this.router.navigate(['people']);
}, 3000);
},
err => {
if (err.error.message) {
this.errorMessage = err.error.message;
}
// it will never be false since it is either undefined or true
if (this.isVerified === false) {
this.router.navigate(['verify']);
}
}
);
}