From 8593d0b5cd530fedc5ece45be0d394f85ce83a72 Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 16 Mar 2024 11:19:21 +0530 Subject: [PATCH] Update/fix login --- src/app/_services/authentication.service.ts | 21 +++++++++------------ src/app/login/login.component.ts | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/app/_services/authentication.service.ts b/src/app/_services/authentication.service.ts index 80bf45d..e66fc88 100644 --- a/src/app/_services/authentication.service.ts +++ b/src/app/_services/authentication.service.ts @@ -54,17 +54,13 @@ export class AuthenticationService { ) } - login(userName: string, password: string): Observable { - let body = JSON.stringify({ - userName: userName, - password: password - }) + login(userName: string, password: string): Observable { + const headers = new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'}) + var formData: any = new URLSearchParams() + formData.set('username', userName) + formData.set('password', password) return this._http.post( - '/auth/login', - body, - { - headers: new HttpHeaders({ 'Content-Type': 'application/json' }) - } + '/api/token', formData, {headers: headers} ).pipe(map( (response: AuthResponse) => { // login successful if there's a jwt token in the response @@ -87,13 +83,14 @@ export class AuthenticationService { this.user.next(new User(userName, token)) // return true to indicate successful login - return true + // return true } else { this.user.next(undefined) this.roles = [] // return false to indicate failed login - return false + // return false } + return response } )) } diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index a139b70..05eaf94 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -41,7 +41,7 @@ export class LoginComponent implements OnInit { this.loading = true this.authenticationService.login(this.formGroup.value.userName, this.formGroup.value.password).subscribe({ next: result => { - if (result === true) { + if (result.access_token) { // login successful this.router.navigate(['/']) } else {