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