Ajout d'un appel pour check la
validité du token
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user