react-toolkits 2.13.7 → 2.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # react-toolkits
2
2
 
3
+ ## 2.13.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d60f77: fix: missing token
8
+
3
9
  ## 2.13.7
4
10
 
5
11
  ### Patch Changes
package/lib/index.js CHANGED
@@ -281,85 +281,85 @@ var init_Interceptors = __esm({
281
281
  getGameId,
282
282
  permissionVersion
283
283
  } = useToolkitsStore((s) => s);
284
- useEffect(() => {
285
- let requestInterceptorId;
286
- let responseInterceptorId;
287
- if (interceptors?.request) {
288
- requestInterceptorId = axios2.interceptors.request.use(...interceptors.request);
289
- } else {
290
- requestInterceptorId = axios2.interceptors.request.use((config) => {
291
- const headers = new AxiosHeaders(config.headers);
292
- config.responseType = config.responseType || "json";
293
- if (token) {
294
- headers.setAuthorization(`Bearer ${token}`);
284
+ let requestInterceptorId;
285
+ let responseInterceptorId;
286
+ if (interceptors?.request) {
287
+ requestInterceptorId = axios2.interceptors.request.use(...interceptors.request);
288
+ } else {
289
+ requestInterceptorId = axios2.interceptors.request.use((config) => {
290
+ const headers = new AxiosHeaders(config.headers);
291
+ config.responseType = config.responseType || "json";
292
+ if (token) {
293
+ headers.setAuthorization(`Bearer ${token}`);
294
+ }
295
+ if (!headers.has(APP_ID_HEADER) && permissionVersion !== "v1" /* V1 */) {
296
+ const gameId = getGameId();
297
+ if (isGlobal || !gameId) {
298
+ headers.set(APP_ID_HEADER, "global");
299
+ } else {
300
+ headers.set(APP_ID_HEADER, gameId);
295
301
  }
296
- if (!headers.has(APP_ID_HEADER) && permissionVersion !== "v1" /* V1 */) {
297
- const gameId = getGameId();
298
- if (isGlobal || !gameId) {
299
- headers.set(APP_ID_HEADER, "global");
302
+ }
303
+ headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
304
+ config.headers = headers;
305
+ return config;
306
+ });
307
+ }
308
+ if (interceptors?.response) {
309
+ responseInterceptorId = axios2.interceptors.response.use(...interceptors.response);
310
+ } else {
311
+ responseInterceptorId = axios2.interceptors.response.use(
312
+ (response) => {
313
+ const responseType = response.request.responseType || "json";
314
+ if (responseType === "json") {
315
+ const data = response.data;
316
+ if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
317
+ return response;
300
318
  } else {
301
- headers.set(APP_ID_HEADER, gameId);
319
+ notification.error({
320
+ message: "Request failed",
321
+ description: data.msg
322
+ });
323
+ throw new Error(data.msg);
302
324
  }
303
325
  }
304
- headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
305
- config.headers = headers;
306
- return config;
307
- });
308
- }
309
- if (interceptors?.response) {
310
- responseInterceptorId = axios2.interceptors.response.use(...interceptors.response);
311
- } else {
312
- responseInterceptorId = axios2.interceptors.response.use(
313
- (response) => {
314
- const responseType = response.request.responseType || "json";
315
- if (responseType === "json") {
316
- const data = response.data;
317
- if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
318
- return response;
319
- } else {
320
- notification.error({
321
- message: "Request failed",
322
- description: data.msg
323
- });
324
- throw new Error(data.msg);
325
- }
326
+ return response;
327
+ },
328
+ (error) => {
329
+ if (isAxiosError(error)) {
330
+ const response = error.response;
331
+ if (!response) {
332
+ throw error;
326
333
  }
327
- return response;
328
- },
329
- (error) => {
330
- if (isAxiosError(error)) {
331
- const response = error.response;
332
- if (!response) {
333
- throw error;
334
- }
335
- if (response.status === 401 || response.status === 412) {
336
- clearToken();
337
- if (response.status === 412) {
338
- setUnregistered();
339
- }
340
- window.location.replace(signInPath);
341
- } else if (response.status === 403) {
342
- notification.error({
343
- message: "Forbidden",
344
- description: "You do not have permission to access this resource."
345
- });
346
- } else {
347
- notification.error({
348
- message: "Request failed",
349
- description: response.data.msg
350
- });
351
- throw new Error(response.data.msg);
334
+ if (response.status === 401 || response.status === 412) {
335
+ clearToken?.();
336
+ if (response.status === 412) {
337
+ setUnregistered();
352
338
  }
339
+ window.location.replace(signInPath);
340
+ } else if (response.status === 403) {
341
+ notification.error({
342
+ message: "Forbidden",
343
+ description: "You do not have permission to access this resource."
344
+ });
345
+ } else {
346
+ notification.error({
347
+ message: "Request failed",
348
+ description: response.data.msg
349
+ });
350
+ throw new Error(response.data.msg);
353
351
  }
354
- throw error;
355
352
  }
356
- );
357
- }
353
+ throw error;
354
+ }
355
+ );
356
+ }
357
+ useEffect(() => {
358
358
  return () => {
359
359
  axios2.interceptors.request.eject(requestInterceptorId);
360
360
  axios2.interceptors.response.eject(responseInterceptorId);
361
361
  };
362
- }, [axios2, interceptors, token, isGlobal, signInPath, clearToken, setUnregistered, getGameId, permissionVersion]);
362
+ }, []);
363
363
  return children;
364
364
  };
365
365
  Interceptors_default = Interceptors;