@micha.bigler/ui-core-micha 2.1.11 → 2.1.12

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.
@@ -46,10 +46,11 @@ apiClient.interceptors.response.use((response) => response, (error) => {
46
46
  var _a, _b, _c, _d;
47
47
  const status = (_b = (_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : null;
48
48
  const data = (_d = (_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data) !== null && _d !== void 0 ? _d : {};
49
- const detail = typeof data.detail === "string" ? data.detail : "";
50
- const isStandard401 = status === 401;
51
- const isDrfAuth403 = status === 403 && detail === "Authentication credentials were not provided.";
52
- if (isStandard401 || isDrfAuth403) {
49
+ const code = typeof data.code === "string" ? data.code : null;
50
+ const i18nKey = typeof data.i18nKey === "string" ? data.i18nKey : null;
51
+ const isAuthStatus = status === 401 || status === 403;
52
+ const isNotAuthenticated = code === "not_authenticated" || i18nKey === "auth.not_authenticated";
53
+ if (isAuthStatus && isNotAuthenticated) {
53
54
  redirectToLoginOnce();
54
55
  }
55
56
  return Promise.reject(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "2.1.11",
3
+ "version": "2.1.12",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "private": false,
@@ -55,12 +55,14 @@ apiClient.interceptors.response.use(
55
55
  (error) => {
56
56
  const status = error?.response?.status ?? null;
57
57
  const data = error?.response?.data ?? {};
58
- const detail = typeof data.detail === "string" ? data.detail : "";
58
+ const code = typeof data.code === "string" ? data.code : null;
59
+ const i18nKey = typeof data.i18nKey === "string" ? data.i18nKey : null;
59
60
 
60
- const isStandard401 = status === 401;
61
- const isDrfAuth403 = status === 403 && detail === "Authentication credentials were not provided.";
61
+ const isAuthStatus = status === 401 || status === 403;
62
+ const isNotAuthenticated =
63
+ code === "not_authenticated" || i18nKey === "auth.not_authenticated";
62
64
 
63
- if (isStandard401 || isDrfAuth403) {
65
+ if (isAuthStatus && isNotAuthenticated) {
64
66
  redirectToLoginOnce();
65
67
  }
66
68
  return Promise.reject(error);
@@ -87,4 +89,4 @@ export async function ensureCsrfToken() {
87
89
  }
88
90
  }
89
91
 
90
- export default apiClient;
92
+ export default apiClient;