Skip to content

Commit 07bb62d

Browse files
author
ctaepper
committed
fix: run tokensetup outside ngzone
1 parent d3ba9d9 commit 07bb62d

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

angular-oauth2-oidc/src/oauth-service.ts

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Optional } from '@angular/core';
1+
import { Injectable, NgZone, Optional } from '@angular/core'
22
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
33
import { Observable } from 'rxjs/Observable';
44
import { Subject } from 'rxjs/Subject';
@@ -67,6 +67,7 @@ export class OAuthService
6767
private inImplicitFlow = false;
6868

6969
constructor(
70+
private ngZone: NgZone,
7071
private http: HttpClient,
7172
@Optional() storage: OAuthStorage,
7273
@Optional() tokenValidationHandler: ValidationHandler,
@@ -262,26 +263,42 @@ export class OAuthService
262263
private setupAccessTokenTimer(): void {
263264
let expiration = this.getAccessTokenExpiration();
264265
let storedAt = this.getAccessTokenStoredAt();
265-
let timeout = this.calcTimeout(storedAt, expiration);
266-
267-
this.accessTokenTimeoutSubscription =
268-
Observable
269-
.of(new OAuthInfoEvent('token_expires', 'access_token'))
270-
.delay(timeout)
271-
.subscribe(e => this.eventsSubject.next(e));
266+
// let timeout = this.calcTimeout(storedAt, expiration);
267+
let timeout = 5000;
268+
269+
this.ngZone.runOutsideAngular(() => {
270+
this.accessTokenTimeoutSubscription =
271+
Observable
272+
.of(new OAuthInfoEvent('token_expires', 'access_token'))
273+
.delay(timeout)
274+
.subscribe(e => {
275+
this.ngZone.run(() => {
276+
console.log('setupAccessTokenTimer')
277+
this.eventsSubject.next(e);
278+
})
279+
});
280+
})
272281
}
273282

274283

275284
private setupIdTokenTimer(): void {
276285
let expiration = this.getIdTokenExpiration();
277286
let storedAt = this.getIdTokenStoredAt();
278-
let timeout = this.calcTimeout(storedAt, expiration);
279-
280-
this.idTokenTimeoutSubscription =
281-
Observable
282-
.of(new OAuthInfoEvent('token_expires', 'id_token'))
283-
.delay(timeout)
284-
.subscribe(e => this.eventsSubject.next(e));
287+
// let timeout = this.calcTimeout(storedAt, expiration);
288+
let timeout = 5000;
289+
290+
this.ngZone.runOutsideAngular(() => {
291+
this.idTokenTimeoutSubscription =
292+
Observable
293+
.of(new OAuthInfoEvent('token_expires', 'id_token'))
294+
.delay(timeout)
295+
.subscribe(e => {
296+
this.ngZone.run(() => {
297+
console.log('setupIdTokenTimer')
298+
this.eventsSubject.next(e);
299+
})
300+
});
301+
})
285302
}
286303

287304
private clearAccessTokenTimer(): void {

0 commit comments

Comments
 (0)