@micha.bigler/ui-core-micha 2.1.12 → 2.1.13
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/auth/apiClient.js +38 -2
- package/package.json +1 -1
- package/src/auth/apiClient.jsx +44 -2
package/dist/auth/apiClient.js
CHANGED
|
@@ -42,12 +42,48 @@ function redirectToLoginOnce() {
|
|
|
42
42
|
window.location.assign("/login");
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
function extractAuthSignal(data) {
|
|
46
|
+
if (!data) {
|
|
47
|
+
return { code: null, i18nKey: null };
|
|
48
|
+
}
|
|
49
|
+
if (typeof data === "string") {
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(data);
|
|
52
|
+
return extractAuthSignal(parsed);
|
|
53
|
+
}
|
|
54
|
+
catch (_a) {
|
|
55
|
+
return { code: null, i18nKey: null };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (typeof data !== "object") {
|
|
59
|
+
return { code: null, i18nKey: null };
|
|
60
|
+
}
|
|
61
|
+
if (typeof data.code === "string" || typeof data.i18nKey === "string") {
|
|
62
|
+
return {
|
|
63
|
+
code: typeof data.code === "string" ? data.code : null,
|
|
64
|
+
i18nKey: typeof data.i18nKey === "string" ? data.i18nKey : null,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (Array.isArray(data.errors) && data.errors.length > 0) {
|
|
68
|
+
const first = data.errors[0] || {};
|
|
69
|
+
return {
|
|
70
|
+
code: typeof first.code === "string" ? first.code : null,
|
|
71
|
+
i18nKey: typeof first.i18nKey === "string" ? first.i18nKey : null,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (data.detail && typeof data.detail === "object") {
|
|
75
|
+
return {
|
|
76
|
+
code: typeof data.detail.code === "string" ? data.detail.code : null,
|
|
77
|
+
i18nKey: typeof data.detail.i18nKey === "string" ? data.detail.i18nKey : null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return { code: null, i18nKey: null };
|
|
81
|
+
}
|
|
45
82
|
apiClient.interceptors.response.use((response) => response, (error) => {
|
|
46
83
|
var _a, _b, _c, _d;
|
|
47
84
|
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
85
|
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
|
|
50
|
-
const i18nKey = typeof data.i18nKey === "string" ? data.i18nKey : null;
|
|
86
|
+
const { code, i18nKey } = extractAuthSignal(data);
|
|
51
87
|
const isAuthStatus = status === 401 || status === 403;
|
|
52
88
|
const isNotAuthenticated = code === "not_authenticated" || i18nKey === "auth.not_authenticated";
|
|
53
89
|
if (isAuthStatus && isNotAuthenticated) {
|
package/package.json
CHANGED
package/src/auth/apiClient.jsx
CHANGED
|
@@ -50,13 +50,55 @@ function redirectToLoginOnce() {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
function extractAuthSignal(data) {
|
|
54
|
+
if (!data) {
|
|
55
|
+
return { code: null, i18nKey: null };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (typeof data === "string") {
|
|
59
|
+
try {
|
|
60
|
+
const parsed = JSON.parse(data);
|
|
61
|
+
return extractAuthSignal(parsed);
|
|
62
|
+
} catch {
|
|
63
|
+
return { code: null, i18nKey: null };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof data !== "object") {
|
|
68
|
+
return { code: null, i18nKey: null };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (typeof data.code === "string" || typeof data.i18nKey === "string") {
|
|
72
|
+
return {
|
|
73
|
+
code: typeof data.code === "string" ? data.code : null,
|
|
74
|
+
i18nKey: typeof data.i18nKey === "string" ? data.i18nKey : null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (Array.isArray(data.errors) && data.errors.length > 0) {
|
|
79
|
+
const first = data.errors[0] || {};
|
|
80
|
+
return {
|
|
81
|
+
code: typeof first.code === "string" ? first.code : null,
|
|
82
|
+
i18nKey: typeof first.i18nKey === "string" ? first.i18nKey : null,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (data.detail && typeof data.detail === "object") {
|
|
87
|
+
return {
|
|
88
|
+
code: typeof data.detail.code === "string" ? data.detail.code : null,
|
|
89
|
+
i18nKey: typeof data.detail.i18nKey === "string" ? data.detail.i18nKey : null,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { code: null, i18nKey: null };
|
|
94
|
+
}
|
|
95
|
+
|
|
53
96
|
apiClient.interceptors.response.use(
|
|
54
97
|
(response) => response,
|
|
55
98
|
(error) => {
|
|
56
99
|
const status = error?.response?.status ?? null;
|
|
57
100
|
const data = error?.response?.data ?? {};
|
|
58
|
-
const
|
|
59
|
-
const i18nKey = typeof data.i18nKey === "string" ? data.i18nKey : null;
|
|
101
|
+
const { code, i18nKey } = extractAuthSignal(data);
|
|
60
102
|
|
|
61
103
|
const isAuthStatus = status === 401 || status === 403;
|
|
62
104
|
const isNotAuthenticated =
|