Petit fix sur l'appel à l'API d'authentification
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -12,6 +12,9 @@ import { User } from '../models/user';
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthenticationService {
|
||||
private readonly headers = new HttpHeaders({
|
||||
'Access-Control-Allow-Origin': environment.apiUrl
|
||||
});
|
||||
private currentUserSubject: BehaviorSubject<User>;
|
||||
public currentUser: Observable<User>;
|
||||
|
||||
@@ -25,7 +28,14 @@ export class AuthenticationService {
|
||||
}
|
||||
|
||||
login(username: string, password: string) {
|
||||
return this.http.post<any>(`${environment.apiUrl}/users/authenticate`, { username, password })
|
||||
const bodyLogin = {
|
||||
login: username,
|
||||
password: password
|
||||
};
|
||||
|
||||
return this.http.post<any>(`${environment.apiUrl}/api/User/Authenticate`, bodyLogin, {
|
||||
headers: this.headers
|
||||
})
|
||||
.pipe(map(user => {
|
||||
// store user details and basic auth credentials in local storage to keep user logged in between page refreshes
|
||||
user.authdata = window.btoa(username + ':' + password);
|
||||
|
||||
Reference in New Issue
Block a user