79343967

Date: 2025-01-09 20:39:02
Score: 1
Natty:
Report link

Thank you for your answer. This is my code from your input.

intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
  if (this.myDomainPattern.test(request.url)) {

    this.accountService.user$
      .pipe(take(1))
      .subscribe({
        next: user => {
          if (user) {
            // Clone from the coming request and add Authorization header to that
            request = request.clone({
              setHeaders: {
                Authorization: `Bearer ${user.jwt}`
              }
            });
          }
        }
      })
  }
  return next.handle(request);
}

The second part causes me to fix more. Therefore I will take time to understand it first (I don't know switchmap inside pipe and return Observable<HttpEvent.

Thanks.

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: D052057