141. Login component - success HttpResponse (#18)

This commit is contained in:
Art
2021-09-17 21:02:43 +03:00
parent 2028ece759
commit 892428a2d0
2 changed files with 15 additions and 6 deletions

View File

@ -5,7 +5,8 @@ import {NotificationService} from "../../service/notification.service";
import {NotificationType} from "../../notification/notification-type"; import {NotificationType} from "../../notification/notification-type";
import {Subscription} from "rxjs"; import {Subscription} from "rxjs";
import {UserLogin} from "../../dto/user-login"; import {UserLogin} from "../../dto/user-login";
import {HttpErrorResponse, HttpResponse} from "@angular/common/http"; import {HttpResponse} from "@angular/common/http";
import {User} from "../../model/user";
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@ -36,9 +37,17 @@ export class LoginComponent implements OnInit, OnDestroy {
let subscription = this.authenticationService let subscription = this.authenticationService
.login(userLogin) .login(userLogin)
.subscribe((response: HttpResponse<any> | HttpErrorResponse) => { .subscribe((response: HttpResponse<User>) => {
const token = response.headers.get("Jwt-Token");
}); const token = response.headers.get("Jwt-Token");
this.authenticationService.saveToken(token!);
this.authenticationService.addUserToLocalStorage(response.body!);
this.router.navigateByUrl('/user/management');
this.showLoading = false;
}
);
this.subscriptions.push(subscription); this.subscriptions.push(subscription);
} }

View File

@ -25,8 +25,8 @@ export class AuthenticationService {
constructor(private httpClient: HttpClient) { constructor(private httpClient: HttpClient) {
} }
public login(userDto: UserLogin): Observable<HttpResponse<any> | HttpErrorResponse> { public login(userDto: UserLogin): Observable<HttpResponse<User>> {
return this.httpClient.post<HttpResponse<any> | HttpErrorResponse> return this.httpClient.post<User>
(`${this.host}/user/login`, userDto, {observe: 'response'}); (`${this.host}/user/login`, userDto, {observe: 'response'});
} }