I have a in interceptor that i'd like to pass data to after it was loaded.
More specifically - my application can be used in either authenticated or unauthenticated state. If use authenticates i'd like to pass the authtoken to the interceptor so it can handle adding the token to the headers for every subsequent request.
I tried making the interceptor injectable and just going something like this.interceptor.auhToken = token
but the act of injections seems to instantiate another instance of the interceptor.
My interceptor is being provided as such
{
provide: HTTP_INTERCEPTORS,
useClass: MainInterceptor,
multi: true,
}
Don't use useClass
. Use useExisting
.
Otherwise you're indeed registering the interceptor class twice under two different tokens.