【发布时间】:2019-01-20 09:48:11
【问题描述】:
在后端的用户模式中,我们在用户模型中有 isVerified。我们将 Mongoose 与 Node.js 一起使用。我们尝试检查 isVerified 是否为假,然后它应该导航到验证路由,但它似乎导航到当结果为真时它应该获得的路由。在数据库中它是错误的。这是代码:
SigninForm: FormGroup;
forbiddenEmails: any;
faTimes = faTimes;
errorMessage: string;
user: any;
isVerified: any;
constructor(
private authService: AuthService,
private router: Router,
private usersService: UsersService,
private tokenService: TokenService) {
}
ngOnInit() {
this.SigninForm = new FormGroup({
'username': new FormControl(null, [Validators.required, Validators.minLength(4)]),
'password': new FormControl(null, [Validators.required,
Validators.minLength(4)
]),
});
}
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 => {
this.tokenService.SetToken(data.token);
this.SigninForm.reset();
setTimeout(() => {
this.router.navigate(['people']);
}, 3000);
},
err => {
if (err.error.message) {
this.errorMessage = err.error.message;
}
if (this.isVerified === false) {
this.router.navigate(['verify']);
}
}
);
}
}
为什么它不从模型中检查 isVerified 是真还是假?
【问题讨论】:
-
您是否尝试过在 loginUser subscribe 函数中输出数据?我假设它会在这里返回登录失败的原因。此外,您只在 getUserById 函数中设置了 isVerified - 您没有使用该函数
-
@wodka 你能解释一下上面的代码示例吗?我试图从 Getuserbyid 获取经过验证的值。
标签: angular typescript angular6