@brggroup/share-lib 0.0.81 → 0.0.83

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.
@@ -129,7 +129,6 @@ var TranslateKey;
129
129
  class AppGlobals {
130
130
  static apiEndpoint;
131
131
  static versionCheck;
132
- static idleTimeInMinutes; // phút
133
132
  static MENU_TYPE = 'toolbar-menu';
134
133
  static pageSizeOptions = [10, 20, 50, 100];
135
134
  static filterSet = {};
@@ -545,22 +544,26 @@ class TokenStorage {
545
544
  }
546
545
 
547
546
  class SessionManagerService {
548
- auth = inject(AuthService);
549
547
  zone = inject(NgZone);
550
548
  idleTimer;
551
549
  refreshTimer;
552
550
  heartbeatTimer;
553
- IDLE_MIN = 15;
551
+ static IDLE_MIN = 15;
554
552
  REFRESH_BEFORE = 120;
555
- IDLE_TIME = this.IDLE_MIN * 60 * 1000;
553
+ get IDLE_TIME() {
554
+ return (SessionManagerService.IDLE_MIN || 0) * 60 * 1000;
555
+ }
556
556
  LEADER_KEY = 'APP_LEADER';
557
557
  HEARTBEAT_KEY = 'APP_LEADER_HEARTBEAT';
558
558
  channel = new BroadcastChannel('APP_SESSION');
559
559
  tabId = crypto.randomUUID();
560
560
  isLeader = false;
561
+ handlers;
561
562
  /* ---------------- START ---------------- */
562
- start() {
563
- console.log('Session start', this.tabId);
563
+ start(handlers) {
564
+ if (this.IDLE_TIME <= 0)
565
+ return;
566
+ this.handlers = handlers;
564
567
  this.listenActivity();
565
568
  this.listenChannel();
566
569
  this.updateActivity();
@@ -654,7 +657,7 @@ class SessionManagerService {
654
657
  if (!this.isLeader)
655
658
  return;
656
659
  try {
657
- const res = await this.auth.refreshToken();
660
+ const res = await this.handlers.refreshToken();
658
661
  if (res?.IsSuccess) {
659
662
  this.channel.postMessage({ type: 'token-refresh' });
660
663
  this.scheduleRefresh();
@@ -675,7 +678,7 @@ class SessionManagerService {
675
678
  this.resetIdle();
676
679
  }
677
680
  if (type === 'logout') {
678
- this.auth.signOut();
681
+ this.handlers.logout();
679
682
  }
680
683
  if (type === 'token-refresh') {
681
684
  this.scheduleRefresh();
@@ -685,7 +688,7 @@ class SessionManagerService {
685
688
  /* ---------------- LOGOUT ---------------- */
686
689
  logout() {
687
690
  this.channel.postMessage({ type: 'logout' });
688
- this.auth.signOut();
691
+ this.handlers.logout();
689
692
  }
690
693
  /* ---------------- UTILS ---------------- */
691
694
  debounce(fn, delay) {
@@ -769,7 +772,10 @@ class AuthService extends HTTPService {
769
772
  this.notiService.success('Đăng nhập thành công');
770
773
  TokenStorage.saveToken(res);
771
774
  /* start session manager */
772
- this.sessionManager.start();
775
+ this.sessionManager.start({
776
+ refreshToken: () => this.refreshToken(),
777
+ logout: () => this.signOut(),
778
+ });
773
779
  if (returnUrl) {
774
780
  this.router.navigateByUrl(returnUrl);
775
781
  }
@@ -791,7 +797,7 @@ class AuthService extends HTTPService {
791
797
  initSession() {
792
798
  const token = TokenStorage.getToken();
793
799
  if (token) {
794
- this.sessionManager.start();
800
+ this.sessionManager.start({ refreshToken: () => this.refreshToken(), logout: () => this.signOut() });
795
801
  }
796
802
  }
797
803
  /* ----------------------------------------