@spidy092/auth-client 1.0.7 → 1.0.8
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/core.js +38 -15
- package/package.json +1 -1
package/core.js
CHANGED
|
@@ -51,26 +51,49 @@ export function logout() {
|
|
|
51
51
|
const { clientKey, authBaseUrl, accountUiUrl } = getConfig();
|
|
52
52
|
const token = getToken();
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
window.location.href = `${accountUiUrl}/login`;
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
54
|
+
console.log('Initiating logout for client:', clientKey);
|
|
58
55
|
|
|
56
|
+
// Clear local storage immediately
|
|
59
57
|
clearToken();
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
method: 'POST',
|
|
64
|
-
credentials: 'include',
|
|
65
|
-
headers: {
|
|
66
|
-
'Authorization': `Bearer ${token}`
|
|
67
|
-
}
|
|
68
|
-
}).catch(console.error);
|
|
58
|
+
sessionStorage.clear();
|
|
59
|
+
// Don't clear localStorage completely - might break other stuff
|
|
60
|
+
// localStorage.clear(); // Remove this line
|
|
69
61
|
|
|
70
|
-
//
|
|
71
|
-
|
|
62
|
+
// Call backend logout if we have a token
|
|
63
|
+
if (token) {
|
|
64
|
+
fetch(`${authBaseUrl}/logout/${clientKey}`, {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
credentials: 'include', // ✅ CRITICAL: This sends cookies
|
|
67
|
+
headers: {
|
|
68
|
+
'Authorization': `Bearer ${token}`,
|
|
69
|
+
'Content-Type': 'application/json'
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.then(response => response.json())
|
|
73
|
+
.then(data => {
|
|
74
|
+
console.log('Backend logout response:', data);
|
|
75
|
+
|
|
76
|
+
// If we get a Keycloak logout URL, redirect there
|
|
77
|
+
if (data.keycloakLogoutUrl) {
|
|
78
|
+
window.location.href = data.keycloakLogoutUrl;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Otherwise redirect to login
|
|
83
|
+
window.location.href = `${accountUiUrl}/login`;
|
|
84
|
+
})
|
|
85
|
+
.catch(error => {
|
|
86
|
+
console.error('Logout error:', error);
|
|
87
|
+
// Always redirect to login even on error
|
|
88
|
+
window.location.href = `${accountUiUrl}/login`;
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
// No token, just redirect to login
|
|
92
|
+
window.location.href = `${accountUiUrl}/login`;
|
|
93
|
+
}
|
|
72
94
|
}
|
|
73
95
|
|
|
96
|
+
|
|
74
97
|
export function handleCallback() {
|
|
75
98
|
const params = new URLSearchParams(window.location.search);
|
|
76
99
|
const accessToken = params.get('access_token');
|