@micha.bigler/ui-core-micha 2.1.5 → 2.1.6

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.
@@ -21,22 +21,22 @@ function redirectToLoginOnce() {
21
21
  redirectingToLogin = true;
22
22
  window.location.assign("/login");
23
23
  }
24
- function isAuthish403(error) {
24
+ apiClient.interceptors.response.use((response) => response, (error) => {
25
25
  var _a, _b, _c, _d;
26
26
  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;
27
- if (status !== 403)
28
- return false;
29
27
  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 : {};
30
- const detail = typeof (data === null || data === void 0 ? void 0 : data.detail) === "string" ? data.detail : "";
31
- // Typical auth/session/CSRF related phrases (keep broad but not too broad)
32
- return /csrf|authentication|credentials|not authenticated|session/i.test(detail);
33
- }
34
- apiClient.interceptors.response.use((response) => response, (error) => {
35
- var _a, _b;
36
- 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;
37
- if (status === 401 || isAuthish403(error)) {
28
+ const detail = typeof data.detail === "string" ? data.detail : "";
29
+ // 1. Fall: Klassisches 401 (Unauthorized)
30
+ const isStandard401 = status === 401;
31
+ // 2. Fall: Django DRF "Fake" 403
32
+ // DRF sendet 403 statt 401 bei SessionAuth, aber mit diesem spezifischen Text.
33
+ // Wir prüfen exakt auf diesen String, um echte 403 (Permission denied) nicht zu erwischen.
34
+ const isDrfAuth403 = status === 403 && detail === "Authentication credentials were not provided.";
35
+ if (isStandard401 || isDrfAuth403) {
38
36
  redirectToLoginOnce();
39
37
  }
38
+ // Alle anderen Fehler (echte 403er, 500er, 404er) werden durchgereicht
39
+ // und müssen von der UI (dem Aufrufer) behandelt werden.
40
40
  return Promise.reject(error);
41
41
  });
42
42
  export async function ensureCsrfToken() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micha.bigler/ui-core-micha",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "private": false,
@@ -26,26 +26,27 @@ function redirectToLoginOnce() {
26
26
  window.location.assign("/login");
27
27
  }
28
28
 
29
- function isAuthish403(error) {
30
- const status = error?.response?.status ?? null;
31
- if (status !== 403) return false;
32
-
33
- const data = error?.response?.data ?? {};
34
- const detail = typeof data?.detail === "string" ? data.detail : "";
35
-
36
- // Typical auth/session/CSRF related phrases (keep broad but not too broad)
37
- return /csrf|authentication|credentials|not authenticated|session/i.test(detail);
38
- }
39
-
40
29
  apiClient.interceptors.response.use(
41
30
  (response) => response,
42
31
  (error) => {
43
32
  const status = error?.response?.status ?? null;
33
+ const data = error?.response?.data ?? {};
34
+ const detail = typeof data.detail === "string" ? data.detail : "";
35
+
36
+ // 1. Fall: Klassisches 401 (Unauthorized)
37
+ const isStandard401 = status === 401;
38
+
39
+ // 2. Fall: Django DRF "Fake" 403
40
+ // DRF sendet 403 statt 401 bei SessionAuth, aber mit diesem spezifischen Text.
41
+ // Wir prüfen exakt auf diesen String, um echte 403 (Permission denied) nicht zu erwischen.
42
+ const isDrfAuth403 = status === 403 && detail === "Authentication credentials were not provided.";
44
43
 
45
- if (status === 401 || isAuthish403(error)) {
44
+ if (isStandard401 || isDrfAuth403) {
46
45
  redirectToLoginOnce();
47
46
  }
48
47
 
48
+ // Alle anderen Fehler (echte 403er, 500er, 404er) werden durchgereicht
49
+ // und müssen von der UI (dem Aufrufer) behandelt werden.
49
50
  return Promise.reject(error);
50
51
  }
51
52
  );
@@ -59,4 +60,4 @@ export async function ensureCsrfToken() {
59
60
  }
60
61
  }
61
62
 
62
- export default apiClient;
63
+ export default apiClient;