20 lines
468 B
TypeScript
20 lines
468 B
TypeScript
import {HttpInterceptorFn} from '@angular/common/http';
|
|
import {inject} from '@angular/core';
|
|
import {AuthService} from '@services/auth.service';
|
|
|
|
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
|
const authService = inject(AuthService);
|
|
const jwt = authService.getJwt();
|
|
|
|
if (jwt) {
|
|
const authReq = req.clone({
|
|
setHeaders: {
|
|
Authorization: `Bearer ${jwt}`
|
|
}
|
|
});
|
|
return next(authReq);
|
|
}
|
|
|
|
return next(req);
|
|
};
|