From 28fc83e173b78f59be553fb514a671a58bfeaa8e Mon Sep 17 00:00:00 2001 From: Nikolay Dolzhenkov Date: Wed, 18 Sep 2019 21:23:26 +0300 Subject: [PATCH] Unsubscribe from 'token_received' events before re-subscribing --- projects/lib/src/oauth-service.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/projects/lib/src/oauth-service.ts b/projects/lib/src/oauth-service.ts index 2ddc2d04..99eb6850 100644 --- a/projects/lib/src/oauth-service.ts +++ b/projects/lib/src/oauth-service.ts @@ -74,6 +74,7 @@ export class OAuthService extends AuthConfig { protected _storage: OAuthStorage; protected accessTokenTimeoutSubscription: Subscription; protected idTokenTimeoutSubscription: Subscription; + protected tokenReceivedSubscription: Subscription; protected sessionCheckEventListener: EventListener; protected jwksUri: string; protected sessionCheckTimer: any; @@ -290,7 +291,10 @@ export class OAuthService extends AuthConfig { 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(); @@ -367,7 +371,7 @@ export class OAuthService extends AuthConfig { /** * DEPRECATED. Use a provider for OAuthStorage instead: * - * + * * { provide: OAuthStorage, useFactory: oAuthStorageFactory } * export function oAuthStorageFactory(): OAuthStorage { return localStorage; } *