docpouch-client 1.1.1 → 1.1.2
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/dist/index.js +71 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -499,12 +499,11 @@ export default class docPouchClient {
|
|
|
499
499
|
if (idToken) {
|
|
500
500
|
url += `&id_token_hint=${idToken}`;
|
|
501
501
|
}
|
|
502
|
-
//
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
this.socket.disconnect();
|
|
502
|
+
// DO NOT clear tokens before redirect - wait for redirect back to determine actual logout status
|
|
503
|
+
// Instead, set a flag to indicate we're in logout process
|
|
504
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
505
|
+
sessionStorage.setItem('docpouch_logout_in_progress', 'true');
|
|
506
|
+
}
|
|
508
507
|
// Redirect to OIDC logout endpoint
|
|
509
508
|
window.location.href = url;
|
|
510
509
|
return;
|
|
@@ -552,12 +551,11 @@ export default class docPouchClient {
|
|
|
552
551
|
else if (this.oidcIdToken) {
|
|
553
552
|
url += `&id_token_hint=${this.oidcIdToken}`;
|
|
554
553
|
}
|
|
555
|
-
//
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
this.socket.disconnect();
|
|
554
|
+
// DO NOT clear tokens before redirect - wait for redirect back to determine actual logout status
|
|
555
|
+
// Instead, set a flag to indicate we're in logout process
|
|
556
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
557
|
+
sessionStorage.setItem('docpouch_logout_in_progress', 'true');
|
|
558
|
+
}
|
|
561
559
|
// Emit OIDC logout event
|
|
562
560
|
this.emit('oidc-logout');
|
|
563
561
|
this.emit('logout');
|
|
@@ -613,18 +611,71 @@ export default class docPouchClient {
|
|
|
613
611
|
* @returns {boolean} True if user was just logged out
|
|
614
612
|
*/
|
|
615
613
|
wasJustLoggedOut() {
|
|
616
|
-
// Check
|
|
614
|
+
// Check if we're in the middle of a logout process
|
|
615
|
+
const logoutInProgress = typeof window !== 'undefined' && window.sessionStorage
|
|
616
|
+
? sessionStorage.getItem('docpouch_logout_in_progress') === 'true'
|
|
617
|
+
: false;
|
|
618
|
+
if (!logoutInProgress) {
|
|
619
|
+
return false;
|
|
620
|
+
}
|
|
621
|
+
// Check URL query parameters for logout confirmation
|
|
617
622
|
const urlParams = new URLSearchParams(window.location.search);
|
|
618
|
-
|
|
619
|
-
|
|
623
|
+
const logoutParam = urlParams.get('logout');
|
|
624
|
+
// If logout parameter is explicitly 'no', user cancelled
|
|
625
|
+
if (logoutParam === 'no') {
|
|
626
|
+
// Clear the logout in progress flag
|
|
627
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
628
|
+
sessionStorage.removeItem('docpouch_logout_in_progress');
|
|
629
|
+
}
|
|
630
|
+
return false;
|
|
620
631
|
}
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
632
|
+
// If logout parameter is 'yes' or 'true', user confirmed logout
|
|
633
|
+
if (logoutParam === 'yes' || logoutParam === 'true') {
|
|
634
|
+
// Clear the logout in progress flag
|
|
635
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
636
|
+
sessionStorage.removeItem('docpouch_logout_in_progress');
|
|
637
|
+
}
|
|
638
|
+
// Clear tokens as user confirmed logout
|
|
639
|
+
this.authToken = null;
|
|
640
|
+
this.clearOidcTokens();
|
|
641
|
+
this.authMethod = 'none';
|
|
642
|
+
if (this.socket.connected)
|
|
643
|
+
this.socket.disconnect();
|
|
626
644
|
return true;
|
|
627
645
|
}
|
|
646
|
+
// If no logout parameter but we were in logout process,
|
|
647
|
+
// check if OIDC provider sent us back without confirmation
|
|
648
|
+
// This could happen if there was an error or user cancelled in another way
|
|
649
|
+
if (logoutParam === null) {
|
|
650
|
+
// Check if this is a post-logout redirect - assume logout was successful
|
|
651
|
+
// unless there's an error parameter
|
|
652
|
+
const errorParam = urlParams.get('error');
|
|
653
|
+
if (!errorParam) {
|
|
654
|
+
// Clear the logout in progress flag
|
|
655
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
656
|
+
sessionStorage.removeItem('docpouch_logout_in_progress');
|
|
657
|
+
}
|
|
658
|
+
// Clear tokens
|
|
659
|
+
this.authToken = null;
|
|
660
|
+
this.clearOidcTokens();
|
|
661
|
+
this.authMethod = 'none';
|
|
662
|
+
if (this.socket.connected)
|
|
663
|
+
this.socket.disconnect();
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
// There was an error, assume logout was cancelled
|
|
668
|
+
// Clear the logout in progress flag
|
|
669
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
670
|
+
sessionStorage.removeItem('docpouch_logout_in_progress');
|
|
671
|
+
}
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// Default case - clear the flag to prevent stuck state
|
|
676
|
+
if (typeof window !== 'undefined' && window.sessionStorage) {
|
|
677
|
+
sessionStorage.removeItem('docpouch_logout_in_progress');
|
|
678
|
+
}
|
|
628
679
|
return false;
|
|
629
680
|
}
|
|
630
681
|
// OIDC Dynamic Client Registration Methods
|