@spidy092/auth-client 2.0.8 → 2.1.1

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 (3) hide show
  1. package/index.js +4 -1
  2. package/package.json +1 -1
  3. package/token.js +9 -9
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // auth-client/index.js
2
2
  import { setConfig, getConfig, isRouterMode } from './config';
3
3
  import { login, logout, handleCallback, refreshToken, resetCallbackState, validateCurrentSession } from './core';
4
- import { getToken, setToken, clearToken, addTokenListener, removeTokenListener, getListenerCount } from './token';
4
+ import { getToken, setToken, clearToken, setRefreshToken, getRefreshToken, clearRefreshToken, addTokenListener, removeTokenListener, getListenerCount } from './token';
5
5
  import api from './api';
6
6
  import { decodeToken, isTokenExpired, isAuthenticated } from './utils/jwt';
7
7
 
@@ -23,6 +23,9 @@ export const auth = {
23
23
  getToken,
24
24
  setToken,
25
25
  clearToken,
26
+ setRefreshToken, // ✅ Refresh token for HTTP dev
27
+ getRefreshToken,
28
+ clearRefreshToken,
26
29
  addTokenListener, // ✅ Export new functions
27
30
  removeTokenListener,
28
31
  getListenerCount, // ✅ Debug function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spidy092/auth-client",
3
- "version": "2.0.8",
3
+ "version": "2.1.1",
4
4
  "description": "Scalable frontend auth SDK for centralized login using Keycloak + Auth Service.",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
package/token.js CHANGED
@@ -53,7 +53,7 @@ function readAccessToken() {
53
53
  // }
54
54
 
55
55
  // const expires = new Date(Date.now() + COOKIE_MAX_AGE * 1000);
56
-
56
+
57
57
  // try {
58
58
  // document.cookie = `${REFRESH_COOKIE}=${encodeURIComponent(token)}; Path=/; SameSite=Lax${secureAttribute()}; Expires=${expires.toUTCString()}`;
59
59
  // } catch (err) {
@@ -66,14 +66,14 @@ function readAccessToken() {
66
66
  // const match = document.cookie
67
67
  // ?.split('; ')
68
68
  // ?.find((row) => row.startsWith(`${REFRESH_COOKIE}=`));
69
-
69
+
70
70
  // if (match) {
71
71
  // return decodeURIComponent(match.split('=')[1]);
72
72
  // }
73
73
  // } catch (err) {
74
74
  // console.warn('Could not read refresh token:', err);
75
75
  // }
76
-
76
+
77
77
  // return null;
78
78
  // }
79
79
 
@@ -149,7 +149,7 @@ export function setRefreshToken(token) {
149
149
  // ✅ SECURITY: Refresh tokens should ONLY be in httpOnly cookies set by server
150
150
  // This function should NOT be used - refresh tokens must come from server cookies
151
151
  // Keeping for backwards compatibility but logging warning
152
-
152
+
153
153
  if (!token) {
154
154
  clearRefreshToken();
155
155
  return;
@@ -157,10 +157,10 @@ export function setRefreshToken(token) {
157
157
 
158
158
  console.warn('⚠️ SECURITY WARNING: setRefreshToken() called - refresh tokens should only be in httpOnly cookies!');
159
159
  console.warn('⚠️ Refresh tokens set client-side are insecure and should be removed');
160
-
160
+
161
161
  // ❌ DO NOT store refresh token in client-side storage
162
162
  // The server sets it in httpOnly cookie, which is the only secure way
163
-
163
+
164
164
  // Only clear any existing client-side storage
165
165
  try {
166
166
  sessionStorage.removeItem(REFRESH_COOKIE);
@@ -174,13 +174,13 @@ export function getRefreshToken() {
174
174
  // We cannot read httpOnly cookies from JavaScript - they're only sent with requests
175
175
  // This function is kept for backwards compatibility but returns null
176
176
  // The refresh endpoint will automatically use the httpOnly cookie via credentials: 'include'
177
-
177
+
178
178
  // ❌ DO NOT try to read refresh token from client-side storage
179
179
  // httpOnly cookies are not accessible via document.cookie
180
-
180
+
181
181
  console.warn('⚠️ getRefreshToken() called - refresh tokens are in httpOnly cookies and cannot be read from JavaScript');
182
182
  console.warn('⚠️ The refresh endpoint will automatically use the httpOnly cookie via credentials: "include"');
183
-
183
+
184
184
  return null; // Refresh token is in httpOnly cookie, not accessible to JavaScript
185
185
  }
186
186