Modif des services avec l'utilisation d'un "BaseService"

This commit is contained in:
Sébastien André
2020-03-13 12:19:05 +01:00
parent eb799946c7
commit e7e7f3f62b
8 changed files with 95 additions and 75 deletions

View File

@@ -1,24 +1,23 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from '../environments/environment';
import { User } from '../models/user';
import { BaseService } from './base.service';
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
private readonly headers = new HttpHeaders({
'Access-Control-Allow-Origin': environment.apiUrl
});
export class AuthenticationService extends BaseService {
private currentUserSubject: BehaviorSubject<User>;
public currentUser: Observable<User>;
constructor(private http: HttpClient) {
super();
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem('currentUser')));
this.currentUser = this.currentUserSubject.asObservable();
}
@@ -33,7 +32,7 @@ export class AuthenticationService {
password: password
};
return this.http.post<any>(`${environment.apiUrl}/api/User/Authenticate`, bodyLogin, {
return this.http.post<any>(`${this.apiUrl}/User/Authenticate`, bodyLogin, {
headers: this.headers
})
.pipe(map(user => {