strapi-custom-auth 1.2.36 → 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 -31
- package/dist/admin/index.mjs +10 -31
- 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,39 +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
|
-
} catch (e) {
|
|
89
|
-
console.log("----fetch---, e", e);
|
|
90
|
-
console.log("----fetch---, e", JSON.stringify(e));
|
|
91
|
-
}
|
|
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;
|
|
92
83
|
}
|
|
93
|
-
console.log("---renewal---");
|
|
94
84
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
95
|
-
console.log("---token---", token);
|
|
96
85
|
if (isTokenExpired(token)) {
|
|
97
|
-
console.log("---Token IS EXPIRED---");
|
|
98
86
|
try {
|
|
99
87
|
token = await renewToken(storage, originalFetch);
|
|
100
|
-
console.log("---Token IS EXPIRED---, token", token);
|
|
101
88
|
console.log("Token renewed successfully");
|
|
102
89
|
} catch (error) {
|
|
103
|
-
console.log("---Token IS EXPIRED---, error", error);
|
|
104
|
-
console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
|
|
105
90
|
console.error("Token renewal failed. Logging out...");
|
|
106
91
|
storage.clear();
|
|
107
92
|
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
@@ -128,14 +113,8 @@ const fetchInterceptor = (storage) => {
|
|
|
128
113
|
};
|
|
129
114
|
try {
|
|
130
115
|
const response = await originalFetch(input, modifiedInit);
|
|
131
|
-
console.log("----originalFetch /2, input", input);
|
|
132
|
-
console.log("----originalFetch /2, input", JSON.stringify(input));
|
|
133
|
-
console.log("----originalFetch /2, modifiedInit", modifiedInit);
|
|
134
|
-
console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
|
|
135
|
-
console.log("----originalFetch /2, response", response);
|
|
136
116
|
if (!response.ok) {
|
|
137
117
|
const errorData = await response.json();
|
|
138
|
-
console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
|
|
139
118
|
console.log("Fetch error:", errorData.error?.message);
|
|
140
119
|
if (response.status === 401) {
|
|
141
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,39 +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
|
-
} catch (e) {
|
|
88
|
-
console.log("----fetch---, e", e);
|
|
89
|
-
console.log("----fetch---, e", JSON.stringify(e));
|
|
90
|
-
}
|
|
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;
|
|
91
82
|
}
|
|
92
|
-
console.log("---renewal---");
|
|
93
83
|
let token = storage.getItem("jwtToken").replace(/"/g, "");
|
|
94
|
-
console.log("---token---", token);
|
|
95
84
|
if (isTokenExpired(token)) {
|
|
96
|
-
console.log("---Token IS EXPIRED---");
|
|
97
85
|
try {
|
|
98
86
|
token = await renewToken(storage, originalFetch);
|
|
99
|
-
console.log("---Token IS EXPIRED---, token", token);
|
|
100
87
|
console.log("Token renewed successfully");
|
|
101
88
|
} catch (error) {
|
|
102
|
-
console.log("---Token IS EXPIRED---, error", error);
|
|
103
|
-
console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
|
|
104
89
|
console.error("Token renewal failed. Logging out...");
|
|
105
90
|
storage.clear();
|
|
106
91
|
if (!window.location.pathname.includes("/admin/auth/login")) {
|
|
@@ -127,14 +112,8 @@ const fetchInterceptor = (storage) => {
|
|
|
127
112
|
};
|
|
128
113
|
try {
|
|
129
114
|
const response = await originalFetch(input, modifiedInit);
|
|
130
|
-
console.log("----originalFetch /2, input", input);
|
|
131
|
-
console.log("----originalFetch /2, input", JSON.stringify(input));
|
|
132
|
-
console.log("----originalFetch /2, modifiedInit", modifiedInit);
|
|
133
|
-
console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
|
|
134
|
-
console.log("----originalFetch /2, response", response);
|
|
135
115
|
if (!response.ok) {
|
|
136
116
|
const errorData = await response.json();
|
|
137
|
-
console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
|
|
138
117
|
console.log("Fetch error:", errorData.error?.message);
|
|
139
118
|
if (response.status === 401) {
|
|
140
119
|
storage.clear();
|
package/package.json
CHANGED