Update/fix login
This commit is contained in:
parent
d51e597376
commit
8593d0b5cd
2 changed files with 10 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue