Mess commit.

This commit is contained in:
Florian THIERRY
2024-08-19 22:42:42 +02:00
parent 32ab1d79c8
commit 56ac024cba
23 changed files with 428 additions and 36 deletions
@@ -0,0 +1,23 @@
import { Observable } from 'rxjs';
import { inject, Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { AuthenticationService } from '../service/authentication.service';
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
private readonly authenticationService = inject(AuthenticationService);
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const jwt = this.authenticationService.getToken();
if (jwt) {
const cloned = request.clone({
headers: request.headers.set('Authorization', `Bearer ${jwt}`)
});
return next.handle(cloned);
}
return next.handle(request);
}
}