import { Injectable } from '@angular/core'; import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http'; import { Observable } from 'rxjs'; import { AuthenticationService } from './authentication.service'; @Injectable() export class AuthInterceptor implements HttpInterceptor { constructor(private authService: AuthenticationService) { } intercept(req: HttpRequest, next: HttpHandler): Observable> { // Skip adding auth header for authentication endpoints if (req.url.includes('/api/auth/authenticate') || req.url.includes('/assets/')) { return next.handle(req); } // Get custom access token const token = this.authService.getCustomAccessToken(); if (token) { // Clone request and add Authorization header const authReq = req.clone({ headers: req.headers.set('Authorization', `Bearer ${token}`) }); return next.handle(authReq); } return next.handle(req); } }