Search code examples
angularrequesteventemitter

Is there a way to pass a value into an Interceptor class?


For background: I have an interceptor that clones a request and inserts a bearer token, I want to add another field to this newRequest called: id with a value I grabbed from an eventEmitter in another class: AppComponent

I have value but I can't pass it to the interceptor like I would to a component via html. Is there a way to do this?


Solution

  • I don't know details but it looks like you need to use localStorage or sessionStorage

    Firstly set your item into local/session storage and then get it, in the interceptor. Please just consider for security precautions and search for which storage type is proper for you.

    take a look: working-with-angular-local-storage and storage types in angular