Update/fix login

This commit is contained in:
phil 2024-03-16 11:19:21 +05:30
parent d51e597376
commit 8593d0b5cd
2 changed files with 10 additions and 13 deletions

View file

@ -54,17 +54,13 @@ export class AuthenticationService {
)
}
login(userName: string, password: string): Observable<boolean> {
let body = JSON.stringify({
userName: userName,
password: password
})
login(userName: string, password: string): Observable<AuthResponse> {
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<AuthResponse>(
'/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
}
))
}

View file

@ -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 {