Mess commit.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user