diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 2b9de9dc..40f520cd 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -75,6 +75,7 @@ export class OAuthService extends AuthConfig implements OnDestroy { protected _storage: OAuthStorage; protected accessTokenTimeoutSubscription: Subscription; protected idTokenTimeoutSubscription: Subscription; + protected tokenReceivedSubscription: Subscription; protected sessionCheckEventListener: EventListener; protected jwksUri: string; protected sessionCheckTimer: any; @@ -304,7 +305,10 @@ export class OAuthService extends AuthConfig implements OnDestroy { this.setupExpirationTimers(); } - this.events.pipe(filter(e => e.type === 'token_received')).subscribe(_ => { + if (this.tokenReceivedSubscription) + this.tokenReceivedSubscription.unsubscribe(); + + this.tokenReceivedSubscription = this.events.pipe(filter(e => e.type === 'token_received')).subscribe(_ => { this.clearAccessTokenTimer(); this.clearIdTokenTimer(); this.setupExpirationTimers();