Ajout du token JWT dans le requêtes
pour être authentifier dans l'API
This commit is contained in:
@@ -25,14 +25,6 @@ export class AuthenticationService extends BaseService {
|
||||
}
|
||||
|
||||
public get currentUserValue(): User {
|
||||
const tmp = localStorage.getItem("currentUser");
|
||||
if (tmp) {
|
||||
const storedUser = JSON.parse(tmp);
|
||||
if (new Date().getTime() > storedUser.expired) {
|
||||
localStorage.removeItem("currentUser");
|
||||
}
|
||||
}
|
||||
|
||||
return this.currentUserSubject.value;
|
||||
}
|
||||
|
||||
@@ -43,15 +35,13 @@ export class AuthenticationService extends BaseService {
|
||||
};
|
||||
|
||||
return this.http
|
||||
.post<any>(`${this.apiUrl}/User/Authenticate`, bodyLogin, {
|
||||
.post<User>(`${this.apiUrl}/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);
|
||||
user.expired = this.dateService.AddDays(new Date(), 1).getTime();
|
||||
|
||||
localStorage.setItem("currentUser", JSON.stringify(user));
|
||||
this.currentUserSubject.next(user);
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user