ОШИБКИ:
ERROR in src/app/common/auth.service.ts(44,30): error TS2339: Property 'success' does not exist on type 'Object'.
src/app/common/auth.service.ts(45,56): error TS2339: Property 'message' does not exist on type 'Object'.
src/app/common/auth.service.ts(47,45): error TS2339: Property 'message' does not exist on type 'Object'.
src/app/common/auth.service.ts(48,46): error TS2339: Property 'token' does not exist on type 'Object'.
src/app/login/login.component.ts(33,30): error TS2339: Property 'success' does not exist on type 'Object | any[]'.
Property 'success' does not exist on type 'Object'.
src/app/login/login.component.ts(34,50): error TS2339: Property 'message' does not exist on type 'Object | any[]'.
Property 'message' does not exist on type 'Object'.
auth.service :login(oUser) {
return this.http.post('http://localhost:1978/api/login', JSON.stringify(oUser), httpOptions).pipe(
tap(user => {
if (user.success) {
this.currentUser = <IUser>user.message;
let userObj: any = {};
userObj.user = user.message;
userObj.token = user.token;
localStorage.setItem('currentUser', JSON.stringify(userObj));
}
}),
catchError(this.handleError('login', []))
);
}
login component.tsloginUser(): void {
if (this.loginForm.dirty && this.loginForm.valid) {
this.authService.login(this.loginForm.value)
.subscribe(data => {
if (data.success === false) {
this.messages.error(data.message);
} else {
this.messages.success('Login successful.');
this.router.navigate(['report']);
}
this.loginForm.reset();
});
}
}
Пример того что отправляю с бэкенда:
oUser.save(function(err) {
if(err){ res.status(400).json({ success: false, message:`Error processing request ${err}`}); }
res.status(201).json({
success: true,
message: 'User created successfully, please login to access your account.'
});
});