strapi-custom-auth 1.2.0 → 1.2.2
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/_chunks/{DynamicExpenses-DJdLL78e.mjs → DynamicExpenses-B9NrrjPS.mjs} +7 -6
- package/dist/_chunks/{DynamicExpenses-CagldSh6.js → DynamicExpenses-CQVuqsh9.js} +7 -6
- package/dist/admin/index.js +1 -101
- package/dist/admin/index.mjs +2 -102
- package/dist/server/index.js +71 -237
- package/dist/server/index.mjs +102 -268
- package/package.json +1 -1
- package/dist/_chunks/CustomLogoutPage-Be-GcZA3.mjs +0 -25
- package/dist/_chunks/CustomLogoutPage-CuntyG5p.js +0 -25
|
@@ -9,13 +9,14 @@ const DynamicExpenses = ({
|
|
|
9
9
|
intlLabel,
|
|
10
10
|
name,
|
|
11
11
|
onChange,
|
|
12
|
+
label,
|
|
12
13
|
placeholder,
|
|
13
14
|
required,
|
|
14
15
|
value
|
|
15
16
|
}) => {
|
|
16
17
|
const [selection, setSelection] = useState("nessuna");
|
|
17
18
|
return /* @__PURE__ */ jsxs("div", { style: { fontSize: "12px" }, children: [
|
|
18
|
-
/* @__PURE__ */ jsx("div", { style: { fontWeight: "bold", fontSize: "12px", marginBottom: "8px" }, children: name }),
|
|
19
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: "bold", fontSize: "12px", marginBottom: "8px" }, children: label ?? name }),
|
|
19
20
|
/* @__PURE__ */ jsx("div", { style: { display: "flex", justifyContent: "start", gap: "15px", marginBottom: "18px" }, children: ["nessuna", "percentuali", "fisse"].map((option) => /* @__PURE__ */ jsxs(
|
|
20
21
|
"label",
|
|
21
22
|
{
|
|
@@ -58,8 +59,8 @@ const DynamicExpenses = ({
|
|
|
58
59
|
},
|
|
59
60
|
placeholder: "",
|
|
60
61
|
required,
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
value: value ? +value.replace("p:", "") : void 0,
|
|
63
|
+
step: 0.01
|
|
63
64
|
}
|
|
64
65
|
),
|
|
65
66
|
selection === "fisse" && /* @__PURE__ */ jsx(
|
|
@@ -71,12 +72,12 @@ const DynamicExpenses = ({
|
|
|
71
72
|
label: "Importo",
|
|
72
73
|
name,
|
|
73
74
|
onValueChange: (value2) => {
|
|
74
|
-
onChange({ target: { name, value: value2 ? `
|
|
75
|
+
onChange({ target: { name, value: value2 ? `f:${value2}` : null } });
|
|
75
76
|
},
|
|
76
|
-
step: 0.01,
|
|
77
77
|
placeholder: "",
|
|
78
78
|
required,
|
|
79
|
-
value: value ? +value.replace("
|
|
79
|
+
value: value ? +value.replace("f:", "") : void 0,
|
|
80
|
+
step: 0.01
|
|
80
81
|
}
|
|
81
82
|
)
|
|
82
83
|
] })
|
|
@@ -11,13 +11,14 @@ const DynamicExpenses = ({
|
|
|
11
11
|
intlLabel,
|
|
12
12
|
name,
|
|
13
13
|
onChange,
|
|
14
|
+
label,
|
|
14
15
|
placeholder,
|
|
15
16
|
required,
|
|
16
17
|
value
|
|
17
18
|
}) => {
|
|
18
19
|
const [selection, setSelection] = React.useState("nessuna");
|
|
19
20
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { fontSize: "12px" }, children: [
|
|
20
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontWeight: "bold", fontSize: "12px", marginBottom: "8px" }, children: name }),
|
|
21
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontWeight: "bold", fontSize: "12px", marginBottom: "8px" }, children: label ?? name }),
|
|
21
22
|
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", justifyContent: "start", gap: "15px", marginBottom: "18px" }, children: ["nessuna", "percentuali", "fisse"].map((option) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
22
23
|
"label",
|
|
23
24
|
{
|
|
@@ -60,8 +61,8 @@ const DynamicExpenses = ({
|
|
|
60
61
|
},
|
|
61
62
|
placeholder: "",
|
|
62
63
|
required,
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
value: value ? +value.replace("p:", "") : void 0,
|
|
65
|
+
step: 0.01
|
|
65
66
|
}
|
|
66
67
|
),
|
|
67
68
|
selection === "fisse" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -73,12 +74,12 @@ const DynamicExpenses = ({
|
|
|
73
74
|
label: "Importo",
|
|
74
75
|
name,
|
|
75
76
|
onValueChange: (value2) => {
|
|
76
|
-
onChange({ target: { name, value: value2 ? `
|
|
77
|
+
onChange({ target: { name, value: value2 ? `f:${value2}` : null } });
|
|
77
78
|
},
|
|
78
|
-
step: 0.01,
|
|
79
79
|
placeholder: "",
|
|
80
80
|
required,
|
|
81
|
-
value: value ? +value.replace("
|
|
81
|
+
value: value ? +value.replace("f:", "") : void 0,
|
|
82
|
+
step: 0.01
|
|
82
83
|
}
|
|
83
84
|
)
|
|
84
85
|
] })
|
package/dist/admin/index.js
CHANGED
|
@@ -27,92 +27,6 @@ const Initializer = ({ setPlugin }) => {
|
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
29
|
const PluginIcon = () => /* @__PURE__ */ jsxRuntime.jsx(icons.PuzzlePiece, {});
|
|
30
|
-
const isTokenExpired = (token) => {
|
|
31
|
-
if (!token) return true;
|
|
32
|
-
try {
|
|
33
|
-
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
34
|
-
return payload.exp * 1e3 < Date.now();
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error("Error decoding token:", error);
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const renewToken = async (storage, originalFetch2) => {
|
|
41
|
-
const refreshToken = storage.getItem("refreshToken");
|
|
42
|
-
if (!refreshToken) {
|
|
43
|
-
throw new Error("No refresh token available");
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
const url = `/strapi-custom-auth/${storage.getItem("provider")}/renew-token`;
|
|
47
|
-
const response = await originalFetch2(url, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
headers: {
|
|
50
|
-
"Content-Type": "application/json"
|
|
51
|
-
},
|
|
52
|
-
body: JSON.stringify({ refreshToken })
|
|
53
|
-
});
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
const errorData = await response.json();
|
|
56
|
-
console.log("Fetch error:", errorData.error?.message);
|
|
57
|
-
throw new Error("Failed to renew token");
|
|
58
|
-
}
|
|
59
|
-
const data = await response.json();
|
|
60
|
-
storage.setItem("jwtToken", `"${data.accessToken}"`);
|
|
61
|
-
storage.setItem("refreshToken", `"${data.refreshToken}"`);
|
|
62
|
-
return data.accessToken;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.log("Error renewing token:", error.message);
|
|
65
|
-
throw error;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const originalFetch = window.fetch;
|
|
69
|
-
const fetchInterceptor = (storage) => {
|
|
70
|
-
window.fetch = async (input, init = {}) => {
|
|
71
|
-
const url = input instanceof Request ? input.url : input;
|
|
72
|
-
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest")) {
|
|
73
|
-
return originalFetch(input, init);
|
|
74
|
-
}
|
|
75
|
-
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
76
|
-
if (isTokenExpired(token)) {
|
|
77
|
-
try {
|
|
78
|
-
token = await renewToken(storage, originalFetch);
|
|
79
|
-
console.log("Token renewed successfully");
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error("Token renewal failed. Logging out...");
|
|
82
|
-
storage.clear();
|
|
83
|
-
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
84
|
-
window.location.href = "/admin/auth/login";
|
|
85
|
-
}
|
|
86
|
-
return Promise.reject(error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const modifiedInit = {
|
|
90
|
-
...init,
|
|
91
|
-
headers: {
|
|
92
|
-
...init.headers,
|
|
93
|
-
Authorization: `Bearer ${token}`
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
const response = await originalFetch(input, modifiedInit);
|
|
98
|
-
if (!response.ok) {
|
|
99
|
-
const errorData = await response.json();
|
|
100
|
-
console.log("Fetch error:", errorData.error?.message);
|
|
101
|
-
if (response.status === 401) {
|
|
102
|
-
storage.clear();
|
|
103
|
-
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
104
|
-
window.location.href = "/admin/auth/login";
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
throw new Error("Request failed");
|
|
108
|
-
}
|
|
109
|
-
return response;
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error("Fetch request failed:", error);
|
|
112
|
-
throw error;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
30
|
const index = {
|
|
117
31
|
register(app) {
|
|
118
32
|
app.addMenuLink({
|
|
@@ -146,25 +60,11 @@ const index = {
|
|
|
146
60
|
defaultMessage: "Create your Dynamic Expenses"
|
|
147
61
|
},
|
|
148
62
|
components: {
|
|
149
|
-
Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-
|
|
63
|
+
Input: async () => Promise.resolve().then(() => require("../_chunks/DynamicExpenses-CQVuqsh9.js")).then((module2) => ({
|
|
150
64
|
default: module2.DynamicExpenses
|
|
151
65
|
}))
|
|
152
66
|
}
|
|
153
67
|
});
|
|
154
|
-
app.addMenuLink({
|
|
155
|
-
to: "/custom-logout",
|
|
156
|
-
icon: icons.SignOut,
|
|
157
|
-
intlLabel: {
|
|
158
|
-
id: "custom-logout.label",
|
|
159
|
-
defaultMessage: "Logout"
|
|
160
|
-
},
|
|
161
|
-
Component: async () => {
|
|
162
|
-
const component = await Promise.resolve().then(() => require("../_chunks/CustomLogoutPage-CuntyG5p.js"));
|
|
163
|
-
return component.default;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
const storage = localStorage.getItem("jwtToken") ? localStorage : sessionStorage;
|
|
167
|
-
fetchInterceptor(storage);
|
|
168
68
|
},
|
|
169
69
|
async registerTrads({ locales }) {
|
|
170
70
|
return Promise.all(
|
package/dist/admin/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { PuzzlePiece
|
|
3
|
+
import { PuzzlePiece } from "@strapi/icons";
|
|
4
4
|
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
5
5
|
const v = glob[path];
|
|
6
6
|
if (v) {
|
|
@@ -26,92 +26,6 @@ const Initializer = ({ setPlugin }) => {
|
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
28
|
const PluginIcon = () => /* @__PURE__ */ jsx(PuzzlePiece, {});
|
|
29
|
-
const isTokenExpired = (token) => {
|
|
30
|
-
if (!token) return true;
|
|
31
|
-
try {
|
|
32
|
-
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
33
|
-
return payload.exp * 1e3 < Date.now();
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error("Error decoding token:", error);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const renewToken = async (storage, originalFetch2) => {
|
|
40
|
-
const refreshToken = storage.getItem("refreshToken");
|
|
41
|
-
if (!refreshToken) {
|
|
42
|
-
throw new Error("No refresh token available");
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const url = `/strapi-custom-auth/${storage.getItem("provider")}/renew-token`;
|
|
46
|
-
const response = await originalFetch2(url, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: {
|
|
49
|
-
"Content-Type": "application/json"
|
|
50
|
-
},
|
|
51
|
-
body: JSON.stringify({ refreshToken })
|
|
52
|
-
});
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
const errorData = await response.json();
|
|
55
|
-
console.log("Fetch error:", errorData.error?.message);
|
|
56
|
-
throw new Error("Failed to renew token");
|
|
57
|
-
}
|
|
58
|
-
const data = await response.json();
|
|
59
|
-
storage.setItem("jwtToken", `"${data.accessToken}"`);
|
|
60
|
-
storage.setItem("refreshToken", `"${data.refreshToken}"`);
|
|
61
|
-
return data.accessToken;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.log("Error renewing token:", error.message);
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const originalFetch = window.fetch;
|
|
68
|
-
const fetchInterceptor = (storage) => {
|
|
69
|
-
window.fetch = async (input, init = {}) => {
|
|
70
|
-
const url = input instanceof Request ? input.url : input;
|
|
71
|
-
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest")) {
|
|
72
|
-
return originalFetch(input, init);
|
|
73
|
-
}
|
|
74
|
-
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
75
|
-
if (isTokenExpired(token)) {
|
|
76
|
-
try {
|
|
77
|
-
token = await renewToken(storage, originalFetch);
|
|
78
|
-
console.log("Token renewed successfully");
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error("Token renewal failed. Logging out...");
|
|
81
|
-
storage.clear();
|
|
82
|
-
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
83
|
-
window.location.href = "/admin/auth/login";
|
|
84
|
-
}
|
|
85
|
-
return Promise.reject(error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const modifiedInit = {
|
|
89
|
-
...init,
|
|
90
|
-
headers: {
|
|
91
|
-
...init.headers,
|
|
92
|
-
Authorization: `Bearer ${token}`
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
try {
|
|
96
|
-
const response = await originalFetch(input, modifiedInit);
|
|
97
|
-
if (!response.ok) {
|
|
98
|
-
const errorData = await response.json();
|
|
99
|
-
console.log("Fetch error:", errorData.error?.message);
|
|
100
|
-
if (response.status === 401) {
|
|
101
|
-
storage.clear();
|
|
102
|
-
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
103
|
-
window.location.href = "/admin/auth/login";
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
throw new Error("Request failed");
|
|
107
|
-
}
|
|
108
|
-
return response;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.error("Fetch request failed:", error);
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
29
|
const index = {
|
|
116
30
|
register(app) {
|
|
117
31
|
app.addMenuLink({
|
|
@@ -145,25 +59,11 @@ const index = {
|
|
|
145
59
|
defaultMessage: "Create your Dynamic Expenses"
|
|
146
60
|
},
|
|
147
61
|
components: {
|
|
148
|
-
Input: async () => import("../_chunks/DynamicExpenses-
|
|
62
|
+
Input: async () => import("../_chunks/DynamicExpenses-B9NrrjPS.mjs").then((module) => ({
|
|
149
63
|
default: module.DynamicExpenses
|
|
150
64
|
}))
|
|
151
65
|
}
|
|
152
66
|
});
|
|
153
|
-
app.addMenuLink({
|
|
154
|
-
to: "/custom-logout",
|
|
155
|
-
icon: SignOut,
|
|
156
|
-
intlLabel: {
|
|
157
|
-
id: "custom-logout.label",
|
|
158
|
-
defaultMessage: "Logout"
|
|
159
|
-
},
|
|
160
|
-
Component: async () => {
|
|
161
|
-
const component = await import("../_chunks/CustomLogoutPage-Be-GcZA3.mjs");
|
|
162
|
-
return component.default;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const storage = localStorage.getItem("jwtToken") ? localStorage : sessionStorage;
|
|
166
|
-
fetchInterceptor(storage);
|
|
167
67
|
},
|
|
168
68
|
async registerTrads({ locales }) {
|
|
169
69
|
return Promise.all(
|