line-gestao-frontend/src/app/interceptors/auth.interceptor.ts

16 lines
381 B
TypeScript

import { HttpInterceptorFn } from '@angular/common/http';
export const authInterceptor: HttpInterceptorFn = (req, next) => {
// ✅ SSR-safe
if (typeof window === 'undefined') return next(req);
const token = localStorage.getItem('token');
if (!token) return next(req);
return next(
req.clone({
setHeaders: { Authorization: `Bearer ${token}` }
})
);
};