Я создал поток, посвященный этим типам вопросов для любых языков программирования здесь .
Также упоминается Java . Вот краткое резюме:
Ваш код отправляет людям маршрут, если http-запрос выполнен успешно, а http-запрос не выполнен, а затем он проверяет, является ли isVerfied ложным, затем перейдите для проверки маршрута. Если ваши поля isVerify исходят из db, то они показывают функцию go to success.
У вас есть несколько проблем в вашем коде
// 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']);
}
}
);
}