15 lines
411 B
TypeScript
15 lines
411 B
TypeScript
import { HttpInterceptorFn } from '@angular/common/http';
|
|
import { inject } from '@angular/core';
|
|
import {AuthService} from "./auth.service";
|
|
|
|
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
|
const token = inject(AuthService).getToken();
|
|
|
|
if (token) {
|
|
req = req.clone({
|
|
setHeaders: { Authorization: `Bearer ${token}` }
|
|
});
|
|
}
|
|
|
|
return next(req);
|
|
}; |