141. Login component - success HttpResponse (#18)
This commit is contained in:
@ -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<any> | HttpErrorResponse) => {
|
||||
const token = response.headers.get("Jwt-Token");
|
||||
});
|
||||
.subscribe((response: HttpResponse<User>) => {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -25,8 +25,8 @@ export class AuthenticationService {
|
||||
constructor(private httpClient: HttpClient) {
|
||||
}
|
||||
|
||||
public login(userDto: UserLogin): Observable<HttpResponse<any> | HttpErrorResponse> {
|
||||
return this.httpClient.post<HttpResponse<any> | HttpErrorResponse>
|
||||
public login(userDto: UserLogin): Observable<HttpResponse<User>> {
|
||||
return this.httpClient.post<User>
|
||||
(`${this.host}/user/login`, userDto, {observe: 'response'});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user