@0xchain/request 1.1.0-beta.34 → 1.1.0-beta.36
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios, { isAxiosError, AxiosError } from "axios";
|
|
2
2
|
import qs from "qs";
|
|
3
|
-
import
|
|
3
|
+
import Cookies from "js-cookie";
|
|
4
4
|
import { logger } from "@0xchain/logger";
|
|
5
5
|
import TokenManager, { isTokenExpired, getToken, removeAllToken, setToken } from "@0xchain/token";
|
|
6
6
|
const isSimplifiedChinese = () => {
|
|
@@ -76,8 +76,8 @@ async function commonHeader(config) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
} else {
|
|
79
|
-
access_token =
|
|
80
|
-
language =
|
|
79
|
+
access_token = Cookies.get("access_token") || "";
|
|
80
|
+
language = Cookies.get("NEXT_LOCALE") || matchSystemLanguage() || "en";
|
|
81
81
|
}
|
|
82
82
|
const isRefreshToken = config.headers?.["isRefreshToken"];
|
|
83
83
|
setHeader(config, "Accept-Language", language);
|
|
@@ -244,6 +244,15 @@ function ResponseInterceptor(response) {
|
|
|
244
244
|
}
|
|
245
245
|
return response;
|
|
246
246
|
}
|
|
247
|
+
function setAuthHeader(config, accessToken) {
|
|
248
|
+
const value = `Bearer ${accessToken}`;
|
|
249
|
+
const h = config.headers;
|
|
250
|
+
if (h?.set && typeof h.set === "function") {
|
|
251
|
+
h.set("Authorization", value);
|
|
252
|
+
} else {
|
|
253
|
+
h.Authorization = value;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
247
256
|
let refreshPromise = null;
|
|
248
257
|
const axiosInstance$1 = axios.create({
|
|
249
258
|
baseURL: process.env.AUTH_INNER_API_URL || process.env.NEXT_PUBLIC_AUTH_URL,
|
|
@@ -264,6 +273,10 @@ async function refreshToken(config) {
|
|
|
264
273
|
const headers = config.headers;
|
|
265
274
|
if (refreshPromise) {
|
|
266
275
|
await refreshPromise;
|
|
276
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
277
|
+
if (accessAfterWait) {
|
|
278
|
+
setAuthHeader(config, accessAfterWait);
|
|
279
|
+
}
|
|
267
280
|
return config;
|
|
268
281
|
}
|
|
269
282
|
let expired = false;
|
|
@@ -280,6 +293,10 @@ async function refreshToken(config) {
|
|
|
280
293
|
}
|
|
281
294
|
if (refreshPromise) {
|
|
282
295
|
await refreshPromise;
|
|
296
|
+
const accessAfterWait = Cookies.get("access_token") || getToken("access_token");
|
|
297
|
+
if (accessAfterWait) {
|
|
298
|
+
setAuthHeader(config, accessAfterWait);
|
|
299
|
+
}
|
|
283
300
|
return config;
|
|
284
301
|
}
|
|
285
302
|
const refreshHeaders = { ...headers };
|
|
@@ -309,6 +326,10 @@ async function refreshToken(config) {
|
|
|
309
326
|
refreshPromise = null;
|
|
310
327
|
});
|
|
311
328
|
await refreshPromise;
|
|
329
|
+
const accessAfterRefresh = Cookies.get("access_token") || getToken("access_token");
|
|
330
|
+
if (accessAfterRefresh) {
|
|
331
|
+
setAuthHeader(config, accessAfterRefresh);
|
|
332
|
+
}
|
|
312
333
|
}
|
|
313
334
|
return config;
|
|
314
335
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,
|
|
1
|
+
{"version":3,"file":"refreshToken.d.ts","sourceRoot":"","sources":["../../src/interceptors/refreshToken.ts"],"names":[],"mappings":"AAAA,OAAc,EAAoB,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAuB5E,wBAA8B,YAAY,CACxC,MAAM,EAAE,0BAA0B,4CAkFnC"}
|