@rasadov/lumoar-sdk 2.0.9 → 2.0.10
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/sdk.js +24 -8
- package/package.json +1 -1
- package/sdk.ts +21 -5
package/dist/sdk.js
CHANGED
|
@@ -52,6 +52,10 @@ export class ApiSDK {
|
|
|
52
52
|
config.headers = {};
|
|
53
53
|
}
|
|
54
54
|
config.headers['Authorization'] = `Bearer ${this.token}`;
|
|
55
|
+
console.log('[SDK] Adding Authorization header to request');
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console.log('[SDK] No token available, request will use only session cookie');
|
|
55
59
|
}
|
|
56
60
|
return config;
|
|
57
61
|
}, (error) => {
|
|
@@ -59,25 +63,37 @@ export class ApiSDK {
|
|
|
59
63
|
});
|
|
60
64
|
// Response interceptor: Extract and update token from backend responses
|
|
61
65
|
this.axiosInstance.interceptors.response.use((response) => {
|
|
62
|
-
var _a;
|
|
63
|
-
|
|
66
|
+
var _a, _b, _c;
|
|
67
|
+
// Try multiple sources for the token
|
|
68
|
+
const authHeader = response.headers['authorization'] || response.headers['Authorization'];
|
|
69
|
+
const dataToken = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.token) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.newToken) || ((_c = response.data) === null || _c === void 0 ? void 0 : _c.authToken);
|
|
70
|
+
const newToken = authHeader || dataToken;
|
|
64
71
|
if (newToken) {
|
|
65
72
|
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
66
73
|
this.setToken(tokenValue);
|
|
67
|
-
console.log('Token automatically updated
|
|
74
|
+
console.log('[SDK] Token automatically updated from backend response');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Debug: Check if header exists but is blocked by CORS
|
|
78
|
+
console.log('[SDK] Response headers available:', Object.keys(response.headers));
|
|
79
|
+
if (!this.token) {
|
|
80
|
+
console.warn('[SDK] No token found in response. If backend sends "authorization" header, check Access-Control-Expose-Headers');
|
|
81
|
+
}
|
|
68
82
|
}
|
|
69
83
|
return response;
|
|
70
84
|
}, (error) => {
|
|
71
|
-
var _a, _b, _c, _d, _e;
|
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
72
86
|
// Even on error, check if backend sent a refreshed token
|
|
73
|
-
const
|
|
87
|
+
const authHeader = ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b['authorization']) || ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d['Authorization']);
|
|
88
|
+
const dataToken = ((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.token) || ((_h = (_g = error.response) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.newToken);
|
|
89
|
+
const newToken = authHeader || dataToken;
|
|
74
90
|
if (newToken) {
|
|
75
91
|
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
76
92
|
this.setToken(tokenValue);
|
|
77
|
-
console.log('Token automatically updated
|
|
93
|
+
console.log('[SDK] Token automatically updated from backend error response');
|
|
78
94
|
}
|
|
79
|
-
if (((
|
|
80
|
-
console.error('Authentication failed - session expired');
|
|
95
|
+
if (((_j = error.response) === null || _j === void 0 ? void 0 : _j.status) === 401) {
|
|
96
|
+
console.error('[SDK] Authentication failed - session expired');
|
|
81
97
|
}
|
|
82
98
|
return Promise.reject(error);
|
|
83
99
|
});
|
package/package.json
CHANGED
package/sdk.ts
CHANGED
|
@@ -102,6 +102,9 @@ export class ApiSDK {
|
|
|
102
102
|
config.headers = {} as any;
|
|
103
103
|
}
|
|
104
104
|
config.headers['Authorization'] = `Bearer ${this.token}`;
|
|
105
|
+
console.log('[SDK] Adding Authorization header to request');
|
|
106
|
+
} else {
|
|
107
|
+
console.log('[SDK] No token available, request will use only session cookie');
|
|
105
108
|
}
|
|
106
109
|
return config;
|
|
107
110
|
}, (error) => {
|
|
@@ -110,23 +113,36 @@ export class ApiSDK {
|
|
|
110
113
|
|
|
111
114
|
// Response interceptor: Extract and update token from backend responses
|
|
112
115
|
this.axiosInstance.interceptors.response.use((response: AxiosResponse) => {
|
|
113
|
-
|
|
116
|
+
// Try multiple sources for the token
|
|
117
|
+
const authHeader = response.headers['authorization'] || response.headers['Authorization'];
|
|
118
|
+
const dataToken = response.data?.token || response.data?.newToken || response.data?.authToken;
|
|
119
|
+
const newToken = authHeader || dataToken;
|
|
120
|
+
|
|
114
121
|
if (newToken) {
|
|
115
122
|
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
116
123
|
this.setToken(tokenValue);
|
|
117
|
-
console.log('Token automatically updated
|
|
124
|
+
console.log('[SDK] Token automatically updated from backend response');
|
|
125
|
+
} else {
|
|
126
|
+
// Debug: Check if header exists but is blocked by CORS
|
|
127
|
+
console.log('[SDK] Response headers available:', Object.keys(response.headers));
|
|
128
|
+
if (!this.token) {
|
|
129
|
+
console.warn('[SDK] No token found in response. If backend sends "authorization" header, check Access-Control-Expose-Headers');
|
|
130
|
+
}
|
|
118
131
|
}
|
|
119
132
|
return response;
|
|
120
133
|
}, (error) => {
|
|
121
134
|
// Even on error, check if backend sent a refreshed token
|
|
122
|
-
const
|
|
135
|
+
const authHeader = error.response?.headers?.['authorization'] || error.response?.headers?.['Authorization'];
|
|
136
|
+
const dataToken = error.response?.data?.token || error.response?.data?.newToken;
|
|
137
|
+
const newToken = authHeader || dataToken;
|
|
138
|
+
|
|
123
139
|
if (newToken) {
|
|
124
140
|
const tokenValue = newToken.replace(/^Bearer /i, '');
|
|
125
141
|
this.setToken(tokenValue);
|
|
126
|
-
console.log('Token automatically updated
|
|
142
|
+
console.log('[SDK] Token automatically updated from backend error response');
|
|
127
143
|
}
|
|
128
144
|
if (error.response?.status === 401) {
|
|
129
|
-
console.error('Authentication failed - session expired');
|
|
145
|
+
console.error('[SDK] Authentication failed - session expired');
|
|
130
146
|
}
|
|
131
147
|
return Promise.reject(error);
|
|
132
148
|
});
|