Ajout du token JWT dans le requêtes

pour être authentifier dans l'API
This commit is contained in:
Sébastien André
2020-03-20 14:18:44 +01:00
parent 4a67b9a5f6
commit 8dc6310080
5 changed files with 135 additions and 77 deletions

View File

@@ -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;