@koalarx/ui 13.2.0 → 13.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -375,12 +375,8 @@ class KoalaOAuth2Service {
375
375
  this.generateState();
376
376
  }
377
377
  ngOnDestroy() {
378
- if (this.eventSubscription) {
379
- this.eventSubscription.unsubscribe();
380
- }
381
- if (this.refreshTokenInterval) {
382
- clearInterval(this.refreshTokenInterval);
383
- }
378
+ this.eventSubscription?.unsubscribe();
379
+ this.refreshTokenInterval?.unsubscribe();
384
380
  }
385
381
  hasOpenIdConfig() {
386
382
  return !!this.openIdOptions;
@@ -474,26 +470,24 @@ class KoalaOAuth2Service {
474
470
  }, 300);
475
471
  }
476
472
  initRefreshTokenInterval(code, refreshToken) {
477
- if (!this.refreshTokenInterval) {
478
- this.refreshTokenInterval = setInterval(() => {
479
- const refreshTokenDate = new Date();
480
- refreshTokenDate.setMinutes(refreshTokenDate.getMinutes() + 1);
481
- const token = this.tokenService.getOAuth2Token();
482
- if (token) {
483
- const expires_in = token.expired;
484
- if (expires_in) {
485
- if (new Date(expires_in) <= refreshTokenDate) {
486
- this.getToken(code, refreshToken);
487
- }
473
+ this.refreshTokenInterval?.unsubscribe();
474
+ this.refreshTokenInterval = interval(1000).subscribe(() => {
475
+ const refreshTokenDate = new Date();
476
+ refreshTokenDate.setMinutes(refreshTokenDate.getMinutes() + 1);
477
+ const token = this.tokenService.getOAuth2Token();
478
+ if (token) {
479
+ const expires_in = token.expired;
480
+ if (expires_in) {
481
+ if (new Date(expires_in) <= refreshTokenDate) {
482
+ this.getToken(code, refreshToken);
488
483
  }
489
484
  }
490
- }, 1000);
491
- }
485
+ }
486
+ });
492
487
  }
493
488
  getToken(code, refreshToken) {
494
489
  if (refreshToken) {
495
- clearInterval(this.refreshTokenInterval);
496
- this.refreshTokenInterval = null;
490
+ this.refreshTokenInterval?.unsubscribe();
497
491
  }
498
492
  const formData = new URLSearchParams();
499
493
  let data = koala({