0

I have an Angular 15 app, which sends quite a bunch of requests. Most of the requests need Authorization with a Bearer token. Therefore I use an HttpInterceptor.

But, there are some requests, which don't need Authorization (i.e. google maps API). However, everyone of my requests has Authorization now, due to the HttpInterceptor.

How do I work around this?

dave0688
  • 5,372
  • 7
  • 33
  • 64
  • You can add an extra parameter to your request / header and check in your interceptor if its there. Depending on that you add the token or not. – Unknown Jan 13 '23 at 14:36
  • Thanks for the answers - I'll implement the context solution, which looks good! – dave0688 Jan 15 '23 at 10:42

1 Answers1

1

Actually there are three ways :

  • you create an array constant which contains the URLS of the links that can bypass the interceptor and skip the token appending for these links only

  • you can add a special header for the request who don't need a token , check if it's in the header in the interceptor , if it's there remove it and don't add your token , if not just trigger the appending

in plus , it's a duplicate of Angular interceptor exclude specific urls , you'll find more answer there .