From 892428a2d0c06426c258cd700e155fbd2c231bc8 Mon Sep 17 00:00:00 2001 From: Art Date: Fri, 17 Sep 2021 21:02:43 +0300 Subject: [PATCH] 141. Login component - success HttpResponse (#18) --- .../src/app/component/login/login.component.ts | 17 +++++++++++++---- .../src/app/service/authentication.service.ts | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/support-portal-frontend/src/app/component/login/login.component.ts b/support-portal-frontend/src/app/component/login/login.component.ts index 6c171c9..a2416cd 100644 --- a/support-portal-frontend/src/app/component/login/login.component.ts +++ b/support-portal-frontend/src/app/component/login/login.component.ts @@ -5,7 +5,8 @@ import {NotificationService} from "../../service/notification.service"; import {NotificationType} from "../../notification/notification-type"; import {Subscription} from "rxjs"; 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({ selector: 'app-login', @@ -36,9 +37,17 @@ export class LoginComponent implements OnInit, OnDestroy { let subscription = this.authenticationService .login(userLogin) - .subscribe((response: HttpResponse | HttpErrorResponse) => { - const token = response.headers.get("Jwt-Token"); - }); + .subscribe((response: HttpResponse) => { + + 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); } diff --git a/support-portal-frontend/src/app/service/authentication.service.ts b/support-portal-frontend/src/app/service/authentication.service.ts index e280c8c..44f3d9f 100644 --- a/support-portal-frontend/src/app/service/authentication.service.ts +++ b/support-portal-frontend/src/app/service/authentication.service.ts @@ -25,8 +25,8 @@ export class AuthenticationService { constructor(private httpClient: HttpClient) { } - public login(userDto: UserLogin): Observable | HttpErrorResponse> { - return this.httpClient.post | HttpErrorResponse> + public login(userDto: UserLogin): Observable> { + return this.httpClient.post (`${this.host}/user/login`, userDto, {observe: 'response'}); }