@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.
Files changed (2) hide show
  1. package/core.js +38 -15
  2. 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
- if (!token) {
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
- // Call logout endpoint
62
- fetch(`${authBaseUrl}/logout/${clientKey}`, {
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
- // Redirect to Account UI logout page
71
- window.location.href = `${accountUiUrl}/logout?client=${clientKey}`;
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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spidy092/auth-client",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Scalable frontend auth SDK for centralized login using Keycloak + Auth Service.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",