import {
HttpHandler,
HttpInterceptor,
HttpParams,
HttpRequest,
} from '@angular/common/http';
import { Injectable } from '@core/services/auth.service';
import { exhaustMap, take } from 'rxjs/operators';
import { AuthenticationService } from './authentication.service';
@Injectable()
export class AuthInterceptorService implements HttpInterceptor {
constructor(private authService: AuthenticationService) { }
intercept(req: HttpRequest<any>, next: HttpHandler) {
return this.authService.checkUser.pipe(
take(1),
exhaustMap((user) => {
if (!user) {
return next.handle(req);
}
const modifiedReq = req.clone({
params: new HttpParams().set('auth', user!.token!),
});
return next.handle(modifiedReq);
})
);
}
}
This specific file serves as an interceptor that adjusts the request URL by including 'auth' query parameters with a token value obtained from the user object. However, it may be challenging to comprehend the inner workings of the exhaustMap function.