Skip to content

Commit 28fc83e

Browse files
author
Nikolay Dolzhenkov
committed
Unsubscribe from 'token_received' events before re-subscribing
1 parent 3586052 commit 28fc83e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

projects/lib/src/oauth-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class OAuthService extends AuthConfig {
7474
protected _storage: OAuthStorage;
7575
protected accessTokenTimeoutSubscription: Subscription;
7676
protected idTokenTimeoutSubscription: Subscription;
77+
protected tokenReceivedSubscription: Subscription;
7778
protected sessionCheckEventListener: EventListener;
7879
protected jwksUri: string;
7980
protected sessionCheckTimer: any;
@@ -290,7 +291,10 @@ export class OAuthService extends AuthConfig {
290291
this.setupExpirationTimers();
291292
}
292293

293-
this.events.pipe(filter(e => e.type === 'token_received')).subscribe(_ => {
294+
if (this.tokenReceivedSubscription)
295+
this.tokenReceivedSubscription.unsubscribe();
296+
297+
this.tokenReceivedSubscription = this.events.pipe(filter(e => e.type === 'token_received')).subscribe(_ => {
294298
this.clearAccessTokenTimer();
295299
this.clearIdTokenTimer();
296300
this.setupExpirationTimers();
@@ -367,7 +371,7 @@ export class OAuthService extends AuthConfig {
367371
/**
368372
* DEPRECATED. Use a provider for OAuthStorage instead:
369373
*
370-
*
374+
*
371375
* { provide: OAuthStorage, useFactory: oAuthStorageFactory }
372376
* export function oAuthStorageFactory(): OAuthStorage { return localStorage; }
373377
*

0 commit comments

Comments
 (0)