@propmix/profet-common-header 3.2.0-beta.2 → 3.2.0-beta.4
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/esm2020/lib/header/header.component.mjs +45 -22
- package/fesm2015/propmix-profet-common-header.mjs +44 -21
- package/fesm2015/propmix-profet-common-header.mjs.map +1 -1
- package/fesm2020/propmix-profet-common-header.mjs +44 -21
- package/fesm2020/propmix-profet-common-header.mjs.map +1 -1
- package/lib/header/header.component.d.ts +2 -0
- package/package.json +1 -1
|
@@ -464,6 +464,8 @@ class HeaderComponent {
|
|
|
464
464
|
this._snackbar = inject(MatSnackBar);
|
|
465
465
|
this._headerSer = inject(CommonHeaderService);
|
|
466
466
|
this._domSanitizer = inject(DomSanitizer);
|
|
467
|
+
this.componentInitTime = 0;
|
|
468
|
+
this.lastProcessedLogoutTimestamp = 0;
|
|
467
469
|
this.INACTIVITY_LIMIT = 30 * 60 * 1000; // 30 minutes
|
|
468
470
|
this.logoutEvent = new EventEmitter();
|
|
469
471
|
this.companyControl = new FormControl();
|
|
@@ -502,9 +504,15 @@ class HeaderComponent {
|
|
|
502
504
|
// },
|
|
503
505
|
// });
|
|
504
506
|
// }
|
|
505
|
-
this
|
|
506
|
-
|
|
507
|
-
|
|
507
|
+
// Capture when this component/app was loaded
|
|
508
|
+
this.componentInitTime = Date.now();
|
|
509
|
+
// Remove legacy boolean check or reset if needed, but primarily we rely on timestamps now.
|
|
510
|
+
// We do NOT want to clear the cookie immediately on init if it's a valid persistent signal,
|
|
511
|
+
// but the timestamp check guards against "looping" on reload.
|
|
512
|
+
// However, if we want to support "fresh login means fresh session", we might just ignore old timestamps (which we do via > initTime check).
|
|
513
|
+
// So distinct cleanup isn't strictly necessary if the login page no longer deletes it.
|
|
514
|
+
// But let's leave it as is or remove it. The user's issue was "delete cookie" logic on LOGIN PAGE caused race condition.
|
|
515
|
+
// Here we just want to start monitoring.
|
|
508
516
|
this.startLogoutCheck();
|
|
509
517
|
}
|
|
510
518
|
resetTimer(isUserActivity = true) {
|
|
@@ -539,16 +547,26 @@ class HeaderComponent {
|
|
|
539
547
|
startLogoutCheck() {
|
|
540
548
|
// Poll for the logout signal cookie (works across ports/subdomains)
|
|
541
549
|
this.logoutCheckInterval = setInterval(() => {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
//
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
550
|
+
const logoutCookie = this._headerSer.getCookie(this._headerSer.SESSION_EXPIRED_KEY);
|
|
551
|
+
if (logoutCookie) {
|
|
552
|
+
const logoutTimestamp = parseInt(logoutCookie, 10);
|
|
553
|
+
// 1. Check if it's a valid number (legacy 'true' string support is irrelevant if we fully switch, but safe to check NaN)
|
|
554
|
+
if (!isNaN(logoutTimestamp)) {
|
|
555
|
+
// 2. Check if this logout event happened AFTER this app was initialized
|
|
556
|
+
// This prevents infinite loops if the user just logged in and the cookie is still there.
|
|
557
|
+
if (logoutTimestamp > this.componentInitTime) {
|
|
558
|
+
// 3. Check if we haven't already processed this exact logout event
|
|
559
|
+
if (logoutTimestamp > this.lastProcessedLogoutTimestamp) {
|
|
560
|
+
this.lastProcessedLogoutTimestamp = logoutTimestamp;
|
|
561
|
+
const lastActive = this._headerSer.getCookie(this._headerSer.LAST_ACTIVE_SESSION_KEY);
|
|
562
|
+
const now = Date.now();
|
|
563
|
+
const lastActiveTime = lastActive ? parseInt(lastActive, 10) : 0;
|
|
564
|
+
const elapsed = now - lastActiveTime;
|
|
565
|
+
const isManual = elapsed < this.INACTIVITY_LIMIT;
|
|
566
|
+
this.handleLogout(false, false, isManual);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
552
570
|
}
|
|
553
571
|
}, 2000); // Check every 2 seconds
|
|
554
572
|
}
|
|
@@ -558,14 +576,17 @@ class HeaderComponent {
|
|
|
558
576
|
// return;
|
|
559
577
|
// }
|
|
560
578
|
if (broadcast) {
|
|
561
|
-
// Set a cookie to signal other tabs/ports
|
|
562
|
-
this
|
|
579
|
+
// Set a cookie to signal other tabs/ports with the current TIMESTAMP
|
|
580
|
+
// This timestamp allows other tabs to know if this is a "new" logout event relative to their session start.
|
|
581
|
+
const now = Date.now();
|
|
582
|
+
this.lastProcessedLogoutTimestamp = now; // Don't logout myself again based on this
|
|
583
|
+
this._headerSer.setCookie(this._headerSer.SESSION_EXPIRED_KEY, now.toString(), 1);
|
|
563
584
|
}
|
|
564
585
|
this.logoutEvent.emit();
|
|
565
586
|
let sessionUrl = this._headerSer.headerConfig.signOutUrl;
|
|
566
587
|
if (this._headerSer.headerConfig.enableLastUrlRedirection) {
|
|
567
588
|
const separator = sessionUrl.includes('?') ? '&' : '?';
|
|
568
|
-
sessionUrl = sessionUrl + separator + '
|
|
589
|
+
sessionUrl = sessionUrl + separator + 'redirectUrl=' + encodeURIComponent(window.location.href);
|
|
569
590
|
}
|
|
570
591
|
// Only add sessionExpired params if it is NOT a manual logout
|
|
571
592
|
if (!isManual) {
|
|
@@ -680,7 +701,9 @@ class HeaderComponent {
|
|
|
680
701
|
onLogoutClick() {
|
|
681
702
|
this.menuTrigger.closeMenu();
|
|
682
703
|
// Sync with other tabs
|
|
683
|
-
|
|
704
|
+
const now = Date.now();
|
|
705
|
+
this.lastProcessedLogoutTimestamp = now;
|
|
706
|
+
this._headerSer.setCookie(this._headerSer.SESSION_EXPIRED_KEY, now.toString(), 1);
|
|
684
707
|
// Clear timers
|
|
685
708
|
if (this.inactivityTimeout)
|
|
686
709
|
clearTimeout(this.inactivityTimeout);
|
|
@@ -688,10 +711,10 @@ class HeaderComponent {
|
|
|
688
711
|
clearInterval(this.logoutCheckInterval);
|
|
689
712
|
this.logoutEvent.emit();
|
|
690
713
|
let sessionUrl = this._headerSer.headerConfig.signOutUrl;
|
|
691
|
-
if (this._headerSer.headerConfig.enableLastUrlRedirection) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
714
|
+
// if (this._headerSer.headerConfig.enableLastUrlRedirection) {
|
|
715
|
+
// const separator = sessionUrl.includes('?') ? '&' : '?';
|
|
716
|
+
// sessionUrl = sessionUrl + separator + 'returnUrl=' + encodeURIComponent(window.location.href);
|
|
717
|
+
// }
|
|
695
718
|
signOut({ global: true, oauth: { redirectUrl: sessionUrl } })
|
|
696
719
|
.then((data) => {
|
|
697
720
|
window.open(sessionUrl, '_self');
|