Hi.
This problem is a side effect of a known problem we have in our SDK: Consider only emitting user$ and idTokenClaims$ if they changed · Issue #105 · auth0/auth0-angular · GitHub
The user$ observable might emit more than you would expect, even more so it looks like it is emitting everytime the interceptor is being used. This is something we should fix in the SDK.
However, even when fixing that, it might still be useful to add a distinctUntilChanged like so:
this.auth.user$.pipe(
map(user => user.sub),
distinctUntilChanged(),
switchMap(sub => this.apiService.getStuff(sub))
);
Another work around could be to use take(1):
this.auth.user$.pipe(
filter(user => Boolean(user)),
take(1),
switchMap(user => this.apiService.getStuff(user.sub))
);
Let me know if that doesn’t help.