Ajout d'un appel pour check la

validité du token
This commit is contained in:
Sébastien André
2020-03-21 17:18:31 +01:00
parent 77c545499d
commit 8c6a187ff0
2 changed files with 26 additions and 11 deletions

View File

@@ -6,7 +6,6 @@ import { map } from "rxjs/operators";
import { User } from "../models/user";
import { BaseService } from "./base.service";
import { DateService } from "./date.service";
@Injectable({
providedIn: "root"
@@ -15,20 +14,22 @@ export class AuthenticationService extends BaseService {
private currentUserSubject: BehaviorSubject<User>;
public currentUser: Observable<User>;
constructor(private http: HttpClient, private dateService: DateService) {
constructor(private http: HttpClient) {
super();
this.currentUserSubject = new BehaviorSubject<User>(
JSON.parse(localStorage.getItem("currentUser"))
);
this.currentUser = this.currentUserSubject.asObservable();
this.alwaysLogin();
}
public get currentUserValue(): User {
return this.currentUserSubject.value;
}
login(username: string, password: string) {
public login(username: string, password: string) {
const bodyLogin = {
login: username,
password: password
@@ -49,7 +50,7 @@ export class AuthenticationService extends BaseService {
);
}
create(newUser: User) {
public create(newUser: User) {
return this.http
.post<any>(`${this.apiUrl}/User`, newUser, {
headers: this.headers
@@ -61,6 +62,12 @@ export class AuthenticationService extends BaseService {
);
}
private alwaysLogin() {
return this.http.get(`${this.apiUrl}/User/AlwayLogin`, {
headers: this.headers
});
}
logout() {
// remove user from local storage to log user out
localStorage.removeItem("currentUser");