strapi-custom-auth 1.2.37 → 1.2.38
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/admin/index.js +10 -37
- package/dist/admin/index.mjs +10 -37
- package/package.json +1 -1
package/dist/admin/index.js
CHANGED
|
@@ -27,7 +27,6 @@ const Initializer = ({ setPlugin }) => {
|
|
|
27
27
|
return null;
|
|
28
28
|
};
|
|
29
29
|
const isTokenExpired = (token) => {
|
|
30
|
-
console.log("---isTokenExpired, token---", token);
|
|
31
30
|
if (!token) return true;
|
|
32
31
|
try {
|
|
33
32
|
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -39,7 +38,6 @@ const isTokenExpired = (token) => {
|
|
|
39
38
|
};
|
|
40
39
|
const renewToken = async (storage, originalFetch2) => {
|
|
41
40
|
const refreshToken = storage.getItem("refreshToken");
|
|
42
|
-
console.log("---renewToken, refreshToken---", refreshToken);
|
|
43
41
|
if (!refreshToken) {
|
|
44
42
|
throw new Error("No refresh token available");
|
|
45
43
|
}
|
|
@@ -69,45 +67,26 @@ const renewToken = async (storage, originalFetch2) => {
|
|
|
69
67
|
const originalFetch = window.fetch;
|
|
70
68
|
const fetchInterceptor = (storage) => {
|
|
71
69
|
window.fetch = async (input, init = {}) => {
|
|
72
|
-
console.log("---input---", JSON.stringify(input));
|
|
73
|
-
console.log("---init---", JSON.stringify(init));
|
|
74
70
|
const url = input instanceof Request ? input.url : input;
|
|
75
|
-
console.log("---url---", url);
|
|
76
71
|
const byPass = init.headers ? await init.headers.get("x-by-pass") : false;
|
|
77
72
|
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData || byPass == true) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
console.log("---skip renewal, init---", JSON.stringify(_init));
|
|
90
|
-
const response = await originalFetch(input, _init);
|
|
91
|
-
console.log("---response--", JSON.stringify(response));
|
|
92
|
-
console.log("---response, json--", await response.json());
|
|
93
|
-
return response;
|
|
94
|
-
} catch (e) {
|
|
95
|
-
console.log("----fetch---, e", e);
|
|
96
|
-
console.log("----fetch---, e", JSON.stringify(e));
|
|
97
|
-
}
|
|
73
|
+
const _token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
74
|
+
const _init = {
|
|
75
|
+
...init,
|
|
76
|
+
headers: {
|
|
77
|
+
...init.headers,
|
|
78
|
+
Authorization: `Bearer ${_token}`
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const response = await originalFetch(input, _init);
|
|
82
|
+
return response;
|
|
98
83
|
}
|
|
99
|
-
console.log("---renewal---");
|
|
100
84
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
101
|
-
console.log("---token---", token);
|
|
102
85
|
if (isTokenExpired(token)) {
|
|
103
|
-
console.log("---Token IS EXPIRED---");
|
|
104
86
|
try {
|
|
105
87
|
token = await renewToken(storage, originalFetch);
|
|
106
|
-
console.log("---Token IS EXPIRED---, token", token);
|
|
107
88
|
console.log("Token renewed successfully");
|
|
108
89
|
} catch (error) {
|
|
109
|
-
console.log("---Token IS EXPIRED---, error", error);
|
|
110
|
-
console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
|
|
111
90
|
console.error("Token renewal failed. Logging out...");
|
|
112
91
|
storage.clear();
|
|
113
92
|
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
@@ -134,14 +113,8 @@ const fetchInterceptor = (storage) => {
|
|
|
134
113
|
};
|
|
135
114
|
try {
|
|
136
115
|
const response = await originalFetch(input, modifiedInit);
|
|
137
|
-
console.log("----originalFetch /2, input", input);
|
|
138
|
-
console.log("----originalFetch /2, input", JSON.stringify(input));
|
|
139
|
-
console.log("----originalFetch /2, modifiedInit", modifiedInit);
|
|
140
|
-
console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
|
|
141
|
-
console.log("----originalFetch /2, response", response);
|
|
142
116
|
if (!response.ok) {
|
|
143
117
|
const errorData = await response.json();
|
|
144
|
-
console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
|
|
145
118
|
console.log("Fetch error:", errorData.error?.message);
|
|
146
119
|
if (response.status === 401) {
|
|
147
120
|
storage.clear();
|
package/dist/admin/index.mjs
CHANGED
|
@@ -26,7 +26,6 @@ const Initializer = ({ setPlugin }) => {
|
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
28
|
const isTokenExpired = (token) => {
|
|
29
|
-
console.log("---isTokenExpired, token---", token);
|
|
30
29
|
if (!token) return true;
|
|
31
30
|
try {
|
|
32
31
|
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -38,7 +37,6 @@ const isTokenExpired = (token) => {
|
|
|
38
37
|
};
|
|
39
38
|
const renewToken = async (storage, originalFetch2) => {
|
|
40
39
|
const refreshToken = storage.getItem("refreshToken");
|
|
41
|
-
console.log("---renewToken, refreshToken---", refreshToken);
|
|
42
40
|
if (!refreshToken) {
|
|
43
41
|
throw new Error("No refresh token available");
|
|
44
42
|
}
|
|
@@ -68,45 +66,26 @@ const renewToken = async (storage, originalFetch2) => {
|
|
|
68
66
|
const originalFetch = window.fetch;
|
|
69
67
|
const fetchInterceptor = (storage) => {
|
|
70
68
|
window.fetch = async (input, init = {}) => {
|
|
71
|
-
console.log("---input---", JSON.stringify(input));
|
|
72
|
-
console.log("---init---", JSON.stringify(init));
|
|
73
69
|
const url = input instanceof Request ? input.url : input;
|
|
74
|
-
console.log("---url---", url);
|
|
75
70
|
const byPass = init.headers ? await init.headers.get("x-by-pass") : false;
|
|
76
71
|
if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData || byPass == true) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
console.log("---skip renewal, init---", JSON.stringify(_init));
|
|
89
|
-
const response = await originalFetch(input, _init);
|
|
90
|
-
console.log("---response--", JSON.stringify(response));
|
|
91
|
-
console.log("---response, json--", await response.json());
|
|
92
|
-
return response;
|
|
93
|
-
} catch (e) {
|
|
94
|
-
console.log("----fetch---, e", e);
|
|
95
|
-
console.log("----fetch---, e", JSON.stringify(e));
|
|
96
|
-
}
|
|
72
|
+
const _token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
73
|
+
const _init = {
|
|
74
|
+
...init,
|
|
75
|
+
headers: {
|
|
76
|
+
...init.headers,
|
|
77
|
+
Authorization: `Bearer ${_token}`
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const response = await originalFetch(input, _init);
|
|
81
|
+
return response;
|
|
97
82
|
}
|
|
98
|
-
console.log("---renewal---");
|
|
99
83
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
100
|
-
console.log("---token---", token);
|
|
101
84
|
if (isTokenExpired(token)) {
|
|
102
|
-
console.log("---Token IS EXPIRED---");
|
|
103
85
|
try {
|
|
104
86
|
token = await renewToken(storage, originalFetch);
|
|
105
|
-
console.log("---Token IS EXPIRED---, token", token);
|
|
106
87
|
console.log("Token renewed successfully");
|
|
107
88
|
} catch (error) {
|
|
108
|
-
console.log("---Token IS EXPIRED---, error", error);
|
|
109
|
-
console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
|
|
110
89
|
console.error("Token renewal failed. Logging out...");
|
|
111
90
|
storage.clear();
|
|
112
91
|
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
@@ -133,14 +112,8 @@ const fetchInterceptor = (storage) => {
|
|
|
133
112
|
};
|
|
134
113
|
try {
|
|
135
114
|
const response = await originalFetch(input, modifiedInit);
|
|
136
|
-
console.log("----originalFetch /2, input", input);
|
|
137
|
-
console.log("----originalFetch /2, input", JSON.stringify(input));
|
|
138
|
-
console.log("----originalFetch /2, modifiedInit", modifiedInit);
|
|
139
|
-
console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
|
|
140
|
-
console.log("----originalFetch /2, response", response);
|
|
141
115
|
if (!response.ok) {
|
|
142
116
|
const errorData = await response.json();
|
|
143
|
-
console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
|
|
144
117
|
console.log("Fetch error:", errorData.error?.message);
|
|
145
118
|
if (response.status === 401) {
|
|
146
119
|
storage.clear();
|
package/package.json
CHANGED