@brggroup/share-lib 0.0.89 → 0.0.90
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.
- package/fesm2022/brggroup-share-lib.mjs +14 -33
- package/fesm2022/brggroup-share-lib.mjs.map +1 -1
- package/lib/auth/auth.service.d.ts +1 -1
- package/lib/auth/auth.service.d.ts.map +1 -1
- package/lib/auth/session-manager.service.d.ts +1 -1
- package/lib/auth/session-manager.service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -567,14 +567,12 @@ class SessionManagerService {
|
|
|
567
567
|
TOKEN_REFRESH_EVENT = 'APP_TOKEN_REFRESH_EVENT';
|
|
568
568
|
tabId = crypto.randomUUID();
|
|
569
569
|
isLeader = false;
|
|
570
|
-
isRunning = false;
|
|
571
570
|
refreshLock = false;
|
|
572
571
|
channel = null;
|
|
573
572
|
/* -------------------------------- START -------------------------------- */
|
|
574
573
|
start(handlers) {
|
|
575
|
-
if (this.IDLE_TIME <= 0
|
|
574
|
+
if (this.IDLE_TIME <= 0)
|
|
576
575
|
return;
|
|
577
|
-
this.isRunning = true;
|
|
578
576
|
this.handlers = handlers;
|
|
579
577
|
if ('BroadcastChannel' in window) {
|
|
580
578
|
this.channel = new BroadcastChannel('APP_SESSION');
|
|
@@ -585,14 +583,11 @@ class SessionManagerService {
|
|
|
585
583
|
this.resetIdle();
|
|
586
584
|
this.electLeader();
|
|
587
585
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// this.channel?.close();
|
|
594
|
-
// this.channel = null;
|
|
595
|
-
// }
|
|
586
|
+
stop() {
|
|
587
|
+
clearTimeout(this.idleTimer);
|
|
588
|
+
clearTimeout(this.refreshTimer);
|
|
589
|
+
clearInterval(this.heartbeatTimer);
|
|
590
|
+
}
|
|
596
591
|
/* -------------------------------- ACTIVITY -------------------------------- */
|
|
597
592
|
listenActivity() {
|
|
598
593
|
const events = ['mousemove', 'keydown', 'click', 'scroll'];
|
|
@@ -601,8 +596,6 @@ class SessionManagerService {
|
|
|
601
596
|
});
|
|
602
597
|
}
|
|
603
598
|
onActivity = this.debounce(() => {
|
|
604
|
-
if (!this.isRunning)
|
|
605
|
-
return;
|
|
606
599
|
this.updateActivity();
|
|
607
600
|
this.resetIdle();
|
|
608
601
|
this.broadcast(this.ACTIVITY_EVENT);
|
|
@@ -612,8 +605,6 @@ class SessionManagerService {
|
|
|
612
605
|
}
|
|
613
606
|
/* -------------------------------- IDLE -------------------------------- */
|
|
614
607
|
resetIdle() {
|
|
615
|
-
if (!this.isRunning)
|
|
616
|
-
return;
|
|
617
608
|
clearTimeout(this.idleTimer);
|
|
618
609
|
const last = Number(localStorage.getItem(this.ACTIVITY_KEY) || Date.now());
|
|
619
610
|
const remain = this.IDLE_TIME - (Date.now() - last);
|
|
@@ -657,7 +648,7 @@ class SessionManagerService {
|
|
|
657
648
|
}
|
|
658
649
|
/* -------------------------------- REFRESH TOKEN -------------------------------- */
|
|
659
650
|
scheduleRefresh() {
|
|
660
|
-
if (!this.isLeader
|
|
651
|
+
if (!this.isLeader)
|
|
661
652
|
return;
|
|
662
653
|
clearTimeout(this.refreshTimer);
|
|
663
654
|
const token = this.handlers.getToken();
|
|
@@ -674,7 +665,7 @@ class SessionManagerService {
|
|
|
674
665
|
}, delay);
|
|
675
666
|
}
|
|
676
667
|
async refreshToken() {
|
|
677
|
-
if (!this.isLeader || this.refreshLock
|
|
668
|
+
if (!this.isLeader || this.refreshLock)
|
|
678
669
|
return;
|
|
679
670
|
this.refreshLock = true;
|
|
680
671
|
try {
|
|
@@ -699,8 +690,6 @@ class SessionManagerService {
|
|
|
699
690
|
if (!this.channel)
|
|
700
691
|
return;
|
|
701
692
|
this.channel.onmessage = (msg) => {
|
|
702
|
-
if (!this.isRunning)
|
|
703
|
-
return;
|
|
704
693
|
const type = msg.data?.type;
|
|
705
694
|
if (type === this.ACTIVITY_EVENT) {
|
|
706
695
|
this.resetIdle();
|
|
@@ -720,8 +709,6 @@ class SessionManagerService {
|
|
|
720
709
|
};
|
|
721
710
|
}
|
|
722
711
|
broadcast(type) {
|
|
723
|
-
if (!this.isRunning)
|
|
724
|
-
return;
|
|
725
712
|
if (this.channel) {
|
|
726
713
|
this.channel.postMessage({ type });
|
|
727
714
|
}
|
|
@@ -737,8 +724,6 @@ class SessionManagerService {
|
|
|
737
724
|
}
|
|
738
725
|
/* -------------------------------- LOGOUT -------------------------------- */
|
|
739
726
|
logout() {
|
|
740
|
-
if (!this.isRunning)
|
|
741
|
-
return;
|
|
742
727
|
this.handlers.logout();
|
|
743
728
|
this.broadcast(this.LOGOUT_EVENT);
|
|
744
729
|
}
|
|
@@ -823,12 +808,6 @@ class AuthService extends HTTPService {
|
|
|
823
808
|
}
|
|
824
809
|
this.notiService.success('Đăng nhập thành công');
|
|
825
810
|
TokenStorage.saveToken(res);
|
|
826
|
-
/* start session manager */
|
|
827
|
-
this.sessionManager.start({
|
|
828
|
-
refreshToken: () => this.refreshToken(),
|
|
829
|
-
logout: () => this.signOut(),
|
|
830
|
-
getToken: () => this.getToken(),
|
|
831
|
-
});
|
|
832
811
|
this.sessionManager.broadcastLogin();
|
|
833
812
|
if (returnUrl) {
|
|
834
813
|
this.router.navigateByUrl(returnUrl);
|
|
@@ -861,10 +840,12 @@ class AuthService extends HTTPService {
|
|
|
861
840
|
/* ----------------------------------------
|
|
862
841
|
LOGOUT
|
|
863
842
|
---------------------------------------- */
|
|
864
|
-
signOut() {
|
|
843
|
+
signOut(broadcastEvent = false) {
|
|
865
844
|
TokenStorage.clearToken();
|
|
866
|
-
|
|
867
|
-
|
|
845
|
+
if (broadcastEvent) {
|
|
846
|
+
this.sessionManager.broadcastLogout();
|
|
847
|
+
}
|
|
848
|
+
this.sessionManager.stop();
|
|
868
849
|
const currentUrl = this.router.routerState.snapshot.url;
|
|
869
850
|
this.router.navigate(['/login'], {
|
|
870
851
|
queryParams: { returnUrl: currentUrl || '/' },
|
|
@@ -6408,7 +6389,7 @@ class LayoutUser extends BaseComponent {
|
|
|
6408
6389
|
this.goto('/admin/user_profile');
|
|
6409
6390
|
}
|
|
6410
6391
|
logout() {
|
|
6411
|
-
this.authService.signOut();
|
|
6392
|
+
this.authService.signOut(true);
|
|
6412
6393
|
}
|
|
6413
6394
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.7", ngImport: i0, type: LayoutUser, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
6414
6395
|
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.1.7", type: LayoutUser, isStandalone: true, selector: "layout-user", usesInheritance: true, ngImport: i0, template: "<nz-badge [nzSize]=\"'small'\" [nzCount]=\"0\">\n <button nz-button nzType=\"text\" nzSize=\"small\">\n <nz-icon nzType=\"bell\" nzTheme=\"outline\" style=\"color: #ffffff\" />\n </button>\n</nz-badge>\n\n<button\n *ngIf=\"!isXSmall && TokenStorage.getOrgName()\"\n [@fadeInOut]\n nz-button\n nzType=\"text\"\n nz-dropdown\n [nzDropdownMenu]=\"menuOrg\"\n style=\"height: 50px; color: #ffffff\"\n>\n <nz-icon nzType=\"cluster\" nzTheme=\"outline\" />\n {{ TokenStorage.getOrgName() }}\n</button>\n\n<nz-dropdown-menu #menuOrg=\"nzDropdownMenu\">\n <ul nz-menu>\n @for (org of lstOrg; track $index) {\n <li *ngIf=\"$index > 0\" nz-menu-divider></li>\n <li nz-menu-item (click)=\"changeOrg(org)\">\n <nz-icon nzType=\"swap\" nzTheme=\"outline\" /> {{ org.Name }}\n </li>\n }\n </ul>\n</nz-dropdown-menu>\n\n<button nz-button nzType=\"text\" nz-dropdown [nzDropdownMenu]=\"menuUser\" style=\"height: 50px; color: #ffffff\">\n <nz-icon nzType=\"user\" nzTheme=\"outline\" />\n {{ TokenStorage.getUserFullname() }}\n</button>\n\n<nz-dropdown-menu #menuUser=\"nzDropdownMenu\">\n <ul nz-menu>\n <li *ngIf=\"!(!isXSmall && TokenStorage.getOrgName())\" nz-menu-item>\n <nz-icon nzType=\"cluster\" nzTheme=\"outline\" /> {{ TokenStorage.getOrgName() }}\n </li>\n <li *ngIf=\"!(!isXSmall && TokenStorage.getOrgName())\" nz-menu-divider></li>\n <li nz-menu-item (click)=\"gotoSetting()\">\n <nz-icon nzType=\"setting\" nzTheme=\"outline\" /> {{ TranslateKey.SETTING | translate }}\n </li>\n <li nz-menu-divider></li>\n <li nz-menu-item (click)=\"logout()\">\n <nz-icon nzType=\"logout\" nzTheme=\"outline\" /> {{ TranslateKey.LOGOUT | translate }}\n </li>\n </ul>\n</nz-dropdown-menu>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: TranslateModule }, { kind: "pipe", type: i3.TranslatePipe, name: "translate" }, { kind: "ngmodule", type: NzLayoutModule }, { kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i1$2.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { kind: "ngmodule", type: NzDropDownModule }, { kind: "directive", type: i4$2.NzMenuDirective, selector: "[nz-menu]", inputs: ["nzInlineIndent", "nzTheme", "nzMode", "nzInlineCollapsed", "nzSelectable"], outputs: ["nzClick"], exportAs: ["nzMenu"] }, { kind: "component", type: i4$2.NzMenuItemComponent, selector: "[nz-menu-item]", inputs: ["nzPaddingLeft", "nzDisabled", "nzSelected", "nzDanger", "nzMatchRouterExact", "nzMatchRouter"], exportAs: ["nzMenuItem"] }, { kind: "directive", type: i4$2.NzMenuDividerDirective, selector: "[nz-menu-divider]", exportAs: ["nzMenuDivider"] }, { kind: "directive", type: i5$3.NzDropDownDirective, selector: "[nz-dropdown]", inputs: ["nzDropdownMenu", "nzTrigger", "nzMatchWidthElement", "nzBackdrop", "nzClickHide", "nzDisabled", "nzVisible", "nzOverlayClassName", "nzOverlayStyle", "nzPlacement"], outputs: ["nzVisibleChange"], exportAs: ["nzDropdown"] }, { kind: "component", type: i5$3.NzDropdownMenuComponent, selector: "nz-dropdown-menu", exportAs: ["nzDropdownMenu"] }, { kind: "directive", type: i5$3.NzDropdownButtonDirective, selector: "[nz-button][nz-dropdown]" }, { kind: "ngmodule", type: NzGridModule }, { kind: "ngmodule", type: NzFlexModule }, { kind: "ngmodule", type: NzButtonModule }, { kind: "component", type: i8.NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }, { kind: "directive", type: i9.ɵNzTransitionPatchDirective, selector: "[nz-button], nz-button-group, [nz-icon], nz-icon, [nz-menu-item], [nz-submenu], nz-select-top-control, nz-select-placeholder, nz-input-group", inputs: ["hidden"] }, { kind: "ngmodule", type: NzTreeModule }, { kind: "ngmodule", type: NzBackTopModule }, { kind: "ngmodule", type: NzDrawerModule }, { kind: "ngmodule", type: FormsModule }, { kind: "ngmodule", type: NzInputModule }, { kind: "ngmodule", type: NzSegmentedModule }, { kind: "ngmodule", type: NzBadgeModule }, { kind: "component", type: i8$1.NzBadgeComponent, selector: "nz-badge", inputs: ["nzShowZero", "nzShowDot", "nzStandalone", "nzDot", "nzOverflowCount", "nzColor", "nzStyle", "nzText", "nzTitle", "nzStatus", "nzCount", "nzOffset", "nzSize"], exportAs: ["nzBadge"] }], animations: [fadeInOut] });
|