import { HttpInterceptorFn } from '@angular/common/http'; import { inject } from '@angular/core'; import { AuthService } from '../auth/auth.service'; export const refreshInterceptor: HttpInterceptorFn = (req, next) => { const authService = inject(AuthService); if (!authService.isRefreshing && authService.user && authService.needsRefreshing()) { authService.isRefreshing = true; authService.refreshToken().subscribe({ next: () => { authService.isRefreshing = false; }, }); } return next(req); };