alex-evo-sh-auth 0.0.15 → 0.0.16
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fe, { createContext as de, useState as I,
|
|
2
|
-
import { Outlet as
|
|
3
|
-
async function
|
|
1
|
+
import fe, { createContext as de, useState as I, useCallback as j, useEffect as N, useContext as H } from "react";
|
|
2
|
+
import { Outlet as X } from "react-router-dom";
|
|
3
|
+
async function me(r) {
|
|
4
4
|
const t = await fetch(`${r.authServer}/refresh`, {
|
|
5
5
|
method: "POST",
|
|
6
6
|
headers: {
|
|
@@ -16,7 +16,7 @@ async function he(r) {
|
|
|
16
16
|
const o = await t.json();
|
|
17
17
|
return localStorage.setItem(r.baseKey + "_access", o.access), o.access;
|
|
18
18
|
}
|
|
19
|
-
class
|
|
19
|
+
class Se {
|
|
20
20
|
constructor(t, o) {
|
|
21
21
|
this.onAuthFail = o, this.config = t;
|
|
22
22
|
}
|
|
@@ -30,39 +30,39 @@ class ge {
|
|
|
30
30
|
}
|
|
31
31
|
async getValidToken() {
|
|
32
32
|
let t = this.getToken();
|
|
33
|
-
return t || (this.refreshPromise || (this.refreshPromise =
|
|
33
|
+
return t || (this.refreshPromise || (this.refreshPromise = me(this.config).then((o) => (this.setToken(o), o)).finally(() => {
|
|
34
34
|
this.refreshPromise = null;
|
|
35
35
|
})), t = await this.refreshPromise, !t && this.onAuthFail && this.onAuthFail(), t);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
class
|
|
38
|
+
class Re {
|
|
39
39
|
authServer;
|
|
40
40
|
clientId;
|
|
41
41
|
redirectUri;
|
|
42
42
|
homePage;
|
|
43
43
|
baseKey;
|
|
44
|
-
constructor(t, o,
|
|
45
|
-
this.authServer = t, this.clientId = o, this.redirectUri =
|
|
44
|
+
constructor(t, o, a, s, i) {
|
|
45
|
+
this.authServer = t, this.clientId = o, this.redirectUri = a, this.homePage = s, this.baseKey = i;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async function
|
|
49
|
-
let
|
|
50
|
-
const
|
|
48
|
+
async function Z(r, t, o = {}, a) {
|
|
49
|
+
let s = r.getToken();
|
|
50
|
+
const i = (d) => fetch(t, {
|
|
51
51
|
...o,
|
|
52
52
|
headers: {
|
|
53
53
|
...o.headers,
|
|
54
54
|
Authorization: d ? `Bearer ${d}` : ""
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
|
-
let
|
|
58
|
-
return
|
|
57
|
+
let f = await i(s);
|
|
58
|
+
return f.status !== 401 ? f : (r.setToken(null), s = await r.getValidToken(), s ? i(s) : (a?.(), f));
|
|
59
59
|
}
|
|
60
60
|
async function z(r) {
|
|
61
|
-
const t = new URLSearchParams(window.location.search), o = t.get("code"),
|
|
61
|
+
const t = new URLSearchParams(window.location.search), o = t.get("code"), a = sessionStorage.getItem("oauth_state"), s = t.get("state");
|
|
62
62
|
if (!o) return;
|
|
63
|
-
if (!
|
|
63
|
+
if (!s || s !== a)
|
|
64
64
|
throw new Error("Invalid OAuth state");
|
|
65
|
-
const
|
|
65
|
+
const i = sessionStorage.getItem("pkce_verifier"), d = await (await fetch(`${r.config.authServer}/token`, {
|
|
66
66
|
method: "POST",
|
|
67
67
|
headers: {
|
|
68
68
|
"Content-Type": "application/json"
|
|
@@ -70,45 +70,45 @@ async function z(r) {
|
|
|
70
70
|
body: JSON.stringify({
|
|
71
71
|
client_id: r.config.clientId,
|
|
72
72
|
code: o,
|
|
73
|
-
code_verifier:
|
|
73
|
+
code_verifier: i
|
|
74
74
|
})
|
|
75
75
|
})).json();
|
|
76
76
|
localStorage.setItem(r.config.baseKey + "_access", d.access), window.history.replaceState({}, document.title, r.config.homePage), window.location.href = r.config.homePage;
|
|
77
77
|
}
|
|
78
|
-
function
|
|
78
|
+
function he(r = 64) {
|
|
79
79
|
const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
80
80
|
let o = "";
|
|
81
|
-
const
|
|
82
|
-
crypto.getRandomValues(
|
|
83
|
-
for (let
|
|
84
|
-
o += t[s
|
|
81
|
+
const a = new Uint8Array(r);
|
|
82
|
+
crypto.getRandomValues(a);
|
|
83
|
+
for (let s = 0; s < a.length; s++)
|
|
84
|
+
o += t[a[s] % t.length];
|
|
85
85
|
return o;
|
|
86
86
|
}
|
|
87
|
-
async function
|
|
88
|
-
const o = new TextEncoder().encode(r),
|
|
89
|
-
return new Uint8Array(
|
|
87
|
+
async function ge(r) {
|
|
88
|
+
const o = new TextEncoder().encode(r), a = await crypto.subtle.digest("SHA-256", o);
|
|
89
|
+
return new Uint8Array(a);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function _e(r) {
|
|
92
92
|
return btoa(String.fromCharCode(...Array.from(r))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
93
93
|
}
|
|
94
|
-
async function
|
|
95
|
-
const t =
|
|
94
|
+
async function C(r) {
|
|
95
|
+
const t = he(64), o = _e(await ge(t));
|
|
96
96
|
sessionStorage.setItem("pkce_verifier", t);
|
|
97
|
-
const
|
|
98
|
-
sessionStorage.setItem("oauth_state",
|
|
99
|
-
const
|
|
97
|
+
const a = crypto.randomUUID();
|
|
98
|
+
sessionStorage.setItem("oauth_state", a);
|
|
99
|
+
const s = new URLSearchParams({
|
|
100
100
|
response_type: "code",
|
|
101
101
|
client_id: r.config.clientId,
|
|
102
102
|
redirect_uri: r.config.redirectUri,
|
|
103
103
|
code_challenge: o,
|
|
104
104
|
code_challenge_method: "S256",
|
|
105
|
-
state:
|
|
105
|
+
state: a
|
|
106
106
|
});
|
|
107
|
-
window.location.href = `${r.config.authServer}/authorize?${
|
|
107
|
+
window.location.href = `${r.config.authServer}/authorize?${s}`;
|
|
108
108
|
}
|
|
109
|
-
async function
|
|
109
|
+
async function q(r) {
|
|
110
110
|
try {
|
|
111
|
-
await
|
|
111
|
+
await Z(r, `${r.config.authServer}/logout`, {
|
|
112
112
|
method: "POST",
|
|
113
113
|
headers: {
|
|
114
114
|
"Content-Type": "application/json"
|
|
@@ -116,7 +116,7 @@ async function M(r) {
|
|
|
116
116
|
body: JSON.stringify({
|
|
117
117
|
client_id: r.config.clientId
|
|
118
118
|
})
|
|
119
|
-
}), localStorage.removeItem(r.config.baseKey + "_access"), await
|
|
119
|
+
}), localStorage.removeItem(r.config.baseKey + "_access"), await C(r);
|
|
120
120
|
} catch (t) {
|
|
121
121
|
console.error(t);
|
|
122
122
|
}
|
|
@@ -132,57 +132,57 @@ const $ = de({
|
|
|
132
132
|
user: null,
|
|
133
133
|
loading: !1
|
|
134
134
|
});
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
function
|
|
138
|
-
if (
|
|
139
|
-
|
|
135
|
+
var S = { exports: {} }, p = {};
|
|
136
|
+
var G;
|
|
137
|
+
function pe() {
|
|
138
|
+
if (G) return p;
|
|
139
|
+
G = 1;
|
|
140
140
|
var r = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
141
|
-
function o(
|
|
142
|
-
var
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
for (var d in
|
|
146
|
-
d !== "key" && (
|
|
147
|
-
} else
|
|
148
|
-
return
|
|
141
|
+
function o(a, s, i) {
|
|
142
|
+
var f = null;
|
|
143
|
+
if (i !== void 0 && (f = "" + i), s.key !== void 0 && (f = "" + s.key), "key" in s) {
|
|
144
|
+
i = {};
|
|
145
|
+
for (var d in s)
|
|
146
|
+
d !== "key" && (i[d] = s[d]);
|
|
147
|
+
} else i = s;
|
|
148
|
+
return s = i.ref, {
|
|
149
149
|
$$typeof: r,
|
|
150
|
-
type:
|
|
151
|
-
key:
|
|
152
|
-
ref:
|
|
153
|
-
props:
|
|
150
|
+
type: a,
|
|
151
|
+
key: f,
|
|
152
|
+
ref: s !== void 0 ? s : null,
|
|
153
|
+
props: i
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
|
-
return
|
|
156
|
+
return p.Fragment = t, p.jsx = o, p.jsxs = o, p;
|
|
157
157
|
}
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
function
|
|
161
|
-
return
|
|
158
|
+
var v = {};
|
|
159
|
+
var K;
|
|
160
|
+
function ve() {
|
|
161
|
+
return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
162
162
|
function r(e) {
|
|
163
163
|
if (e == null) return null;
|
|
164
164
|
if (typeof e == "function")
|
|
165
|
-
return e.$$typeof ===
|
|
165
|
+
return e.$$typeof === ce ? null : e.displayName || e.name || null;
|
|
166
166
|
if (typeof e == "string") return e;
|
|
167
167
|
switch (e) {
|
|
168
168
|
case w:
|
|
169
169
|
return "Fragment";
|
|
170
170
|
case ee:
|
|
171
171
|
return "Profiler";
|
|
172
|
-
case
|
|
172
|
+
case M:
|
|
173
173
|
return "StrictMode";
|
|
174
174
|
case oe:
|
|
175
175
|
return "Suspense";
|
|
176
|
-
case
|
|
176
|
+
case se:
|
|
177
177
|
return "SuspenseList";
|
|
178
|
-
case
|
|
178
|
+
case ie:
|
|
179
179
|
return "Activity";
|
|
180
180
|
}
|
|
181
181
|
if (typeof e == "object")
|
|
182
182
|
switch (typeof e.tag == "number" && console.error(
|
|
183
183
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
184
184
|
), e.$$typeof) {
|
|
185
|
-
case
|
|
185
|
+
case Q:
|
|
186
186
|
return "Portal";
|
|
187
187
|
case te:
|
|
188
188
|
return e.displayName || "Context";
|
|
@@ -191,7 +191,7 @@ function Ee() {
|
|
|
191
191
|
case ne:
|
|
192
192
|
var n = e.render;
|
|
193
193
|
return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
194
|
-
case
|
|
194
|
+
case ae:
|
|
195
195
|
return n = e.displayName || null, n !== null ? n : r(e.type) || "Memo";
|
|
196
196
|
case k:
|
|
197
197
|
n = e._payload, e = e._init;
|
|
@@ -214,15 +214,15 @@ function Ee() {
|
|
|
214
214
|
}
|
|
215
215
|
if (n) {
|
|
216
216
|
n = console;
|
|
217
|
-
var
|
|
218
|
-
return
|
|
217
|
+
var c = n.error, l = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
218
|
+
return c.call(
|
|
219
219
|
n,
|
|
220
220
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
221
|
-
|
|
221
|
+
l
|
|
222
222
|
), t(e);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
function
|
|
225
|
+
function a(e) {
|
|
226
226
|
if (e === w) return "<>";
|
|
227
227
|
if (typeof e == "object" && e !== null && e.$$typeof === k)
|
|
228
228
|
return "<...>";
|
|
@@ -233,14 +233,14 @@ function Ee() {
|
|
|
233
233
|
return "<...>";
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function s() {
|
|
237
237
|
var e = P.A;
|
|
238
238
|
return e === null ? null : e.getOwner();
|
|
239
239
|
}
|
|
240
|
-
function
|
|
240
|
+
function i() {
|
|
241
241
|
return Error("react-stack-top-frame");
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function f(e) {
|
|
244
244
|
if (F.call(e, "key")) {
|
|
245
245
|
var n = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
246
246
|
if (n && n.isReactWarning) return !1;
|
|
@@ -248,34 +248,34 @@ function Ee() {
|
|
|
248
248
|
return e.key !== void 0;
|
|
249
249
|
}
|
|
250
250
|
function d(e, n) {
|
|
251
|
-
function
|
|
251
|
+
function c() {
|
|
252
252
|
L || (L = !0, console.error(
|
|
253
253
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
254
254
|
n
|
|
255
255
|
));
|
|
256
256
|
}
|
|
257
|
-
|
|
258
|
-
get:
|
|
257
|
+
c.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
258
|
+
get: c,
|
|
259
259
|
configurable: !0
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
|
-
function
|
|
262
|
+
function R() {
|
|
263
263
|
var e = r(this.type);
|
|
264
264
|
return D[e] || (D[e] = !0, console.error(
|
|
265
265
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
266
266
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
267
267
|
}
|
|
268
|
-
function
|
|
269
|
-
var
|
|
268
|
+
function b(e, n, c, l, T, O) {
|
|
269
|
+
var u = c.ref;
|
|
270
270
|
return e = {
|
|
271
271
|
$$typeof: Y,
|
|
272
272
|
type: e,
|
|
273
273
|
key: n,
|
|
274
|
-
props:
|
|
275
|
-
_owner:
|
|
276
|
-
}, (
|
|
274
|
+
props: c,
|
|
275
|
+
_owner: l
|
|
276
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
277
277
|
enumerable: !1,
|
|
278
|
-
get:
|
|
278
|
+
get: R
|
|
279
279
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
280
280
|
configurable: !1,
|
|
281
281
|
enumerable: !1,
|
|
@@ -290,7 +290,7 @@ function Ee() {
|
|
|
290
290
|
configurable: !1,
|
|
291
291
|
enumerable: !1,
|
|
292
292
|
writable: !0,
|
|
293
|
-
value:
|
|
293
|
+
value: T
|
|
294
294
|
}), Object.defineProperty(e, "_debugTask", {
|
|
295
295
|
configurable: !1,
|
|
296
296
|
enumerable: !1,
|
|
@@ -298,173 +298,173 @@ function Ee() {
|
|
|
298
298
|
value: O
|
|
299
299
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
300
300
|
}
|
|
301
|
-
function
|
|
302
|
-
var
|
|
303
|
-
if (
|
|
304
|
-
if (
|
|
305
|
-
if (le(
|
|
306
|
-
for (
|
|
307
|
-
|
|
308
|
-
Object.freeze && Object.freeze(
|
|
301
|
+
function _(e, n, c, l, T, O) {
|
|
302
|
+
var u = n.children;
|
|
303
|
+
if (u !== void 0)
|
|
304
|
+
if (l)
|
|
305
|
+
if (le(u)) {
|
|
306
|
+
for (l = 0; l < u.length; l++)
|
|
307
|
+
m(u[l]);
|
|
308
|
+
Object.freeze && Object.freeze(u);
|
|
309
309
|
} else
|
|
310
310
|
console.error(
|
|
311
311
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
312
312
|
);
|
|
313
|
-
else
|
|
313
|
+
else m(u);
|
|
314
314
|
if (F.call(n, "key")) {
|
|
315
|
-
|
|
316
|
-
var
|
|
315
|
+
u = r(e);
|
|
316
|
+
var h = Object.keys(n).filter(function(ue) {
|
|
317
317
|
return ue !== "key";
|
|
318
318
|
});
|
|
319
|
-
|
|
319
|
+
l = 0 < h.length ? "{key: someKey, " + h.join(": ..., ") + ": ...}" : "{key: someKey}", W[u + l] || (h = 0 < h.length ? "{" + h.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
320
320
|
`A props object containing a "key" prop is being spread into JSX:
|
|
321
321
|
let props = %s;
|
|
322
322
|
<%s {...props} />
|
|
323
323
|
React keys must be passed directly to JSX without using spread:
|
|
324
324
|
let props = %s;
|
|
325
325
|
<%s key={someKey} {...props} />`,
|
|
326
|
+
l,
|
|
326
327
|
u,
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
), W[f + u] = !0);
|
|
328
|
+
h,
|
|
329
|
+
u
|
|
330
|
+
), W[u + l] = !0);
|
|
331
331
|
}
|
|
332
|
-
if (
|
|
333
|
-
|
|
332
|
+
if (u = null, c !== void 0 && (o(c), u = "" + c), f(n) && (o(n.key), u = "" + n.key), "key" in n) {
|
|
333
|
+
c = {};
|
|
334
334
|
for (var x in n)
|
|
335
|
-
x !== "key" && (
|
|
336
|
-
} else
|
|
337
|
-
return
|
|
338
|
-
|
|
335
|
+
x !== "key" && (c[x] = n[x]);
|
|
336
|
+
} else c = n;
|
|
337
|
+
return u && d(
|
|
338
|
+
c,
|
|
339
339
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
340
|
-
),
|
|
340
|
+
), b(
|
|
341
341
|
e,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
342
|
+
u,
|
|
343
|
+
c,
|
|
344
|
+
s(),
|
|
345
|
+
T,
|
|
346
346
|
O
|
|
347
347
|
);
|
|
348
348
|
}
|
|
349
|
-
function v(e) {
|
|
350
|
-
m(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === k && (e._payload.status === "fulfilled" ? m(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
351
|
-
}
|
|
352
349
|
function m(e) {
|
|
350
|
+
E(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === k && (e._payload.status === "fulfilled" ? E(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
351
|
+
}
|
|
352
|
+
function E(e) {
|
|
353
353
|
return typeof e == "object" && e !== null && e.$$typeof === Y;
|
|
354
354
|
}
|
|
355
|
-
var
|
|
355
|
+
var y = fe, Y = /* @__PURE__ */ Symbol.for("react.transitional.element"), Q = /* @__PURE__ */ Symbol.for("react.portal"), w = /* @__PURE__ */ Symbol.for("react.fragment"), M = /* @__PURE__ */ Symbol.for("react.strict_mode"), ee = /* @__PURE__ */ Symbol.for("react.profiler"), re = /* @__PURE__ */ Symbol.for("react.consumer"), te = /* @__PURE__ */ Symbol.for("react.context"), ne = /* @__PURE__ */ Symbol.for("react.forward_ref"), oe = /* @__PURE__ */ Symbol.for("react.suspense"), se = /* @__PURE__ */ Symbol.for("react.suspense_list"), ae = /* @__PURE__ */ Symbol.for("react.memo"), k = /* @__PURE__ */ Symbol.for("react.lazy"), ie = /* @__PURE__ */ Symbol.for("react.activity"), ce = /* @__PURE__ */ Symbol.for("react.client.reference"), P = y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, le = Array.isArray, A = console.createTask ? console.createTask : function() {
|
|
356
356
|
return null;
|
|
357
357
|
};
|
|
358
|
-
|
|
358
|
+
y = {
|
|
359
359
|
react_stack_bottom_frame: function(e) {
|
|
360
360
|
return e();
|
|
361
361
|
}
|
|
362
362
|
};
|
|
363
|
-
var L, D = {}, J =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
)(), V = A(
|
|
367
|
-
|
|
368
|
-
var
|
|
369
|
-
return
|
|
363
|
+
var L, D = {}, J = y.react_stack_bottom_frame.bind(
|
|
364
|
+
y,
|
|
365
|
+
i
|
|
366
|
+
)(), V = A(a(i)), W = {};
|
|
367
|
+
v.Fragment = w, v.jsx = function(e, n, c) {
|
|
368
|
+
var l = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
369
|
+
return _(
|
|
370
370
|
e,
|
|
371
371
|
n,
|
|
372
|
-
|
|
372
|
+
c,
|
|
373
373
|
!1,
|
|
374
|
-
|
|
375
|
-
|
|
374
|
+
l ? Error("react-stack-top-frame") : J,
|
|
375
|
+
l ? A(a(e)) : V
|
|
376
376
|
);
|
|
377
|
-
},
|
|
378
|
-
var
|
|
379
|
-
return
|
|
377
|
+
}, v.jsxs = function(e, n, c) {
|
|
378
|
+
var l = 1e4 > P.recentlyCreatedOwnerStacks++;
|
|
379
|
+
return _(
|
|
380
380
|
e,
|
|
381
381
|
n,
|
|
382
|
-
|
|
382
|
+
c,
|
|
383
383
|
!0,
|
|
384
|
-
|
|
385
|
-
|
|
384
|
+
l ? Error("react-stack-top-frame") : J,
|
|
385
|
+
l ? A(a(e)) : V
|
|
386
386
|
);
|
|
387
387
|
};
|
|
388
|
-
})()),
|
|
388
|
+
})()), v;
|
|
389
389
|
}
|
|
390
|
-
var
|
|
391
|
-
function
|
|
392
|
-
return
|
|
390
|
+
var B;
|
|
391
|
+
function be() {
|
|
392
|
+
return B || (B = 1, process.env.NODE_ENV === "production" ? S.exports = pe() : S.exports = ve()), S.exports;
|
|
393
393
|
}
|
|
394
|
-
var
|
|
395
|
-
const
|
|
396
|
-
const [o,
|
|
397
|
-
|
|
398
|
-
const
|
|
399
|
-
if (!
|
|
400
|
-
|
|
394
|
+
var g = be();
|
|
395
|
+
const we = ({ children: r, authManager: t }) => {
|
|
396
|
+
const [o, a] = I(null), [s, i] = I(!0), f = j(async () => {
|
|
397
|
+
i(!0);
|
|
398
|
+
const b = localStorage.getItem(t.config.baseKey + "_access");
|
|
399
|
+
if (!b) {
|
|
400
|
+
a(null), i(!1);
|
|
401
401
|
return;
|
|
402
402
|
}
|
|
403
403
|
try {
|
|
404
|
-
const
|
|
404
|
+
const _ = await Z(t, `${t.config.authServer}/me`, {
|
|
405
405
|
headers: {
|
|
406
|
-
Authorization: `Bearer ${
|
|
406
|
+
Authorization: `Bearer ${b}`
|
|
407
407
|
}
|
|
408
408
|
});
|
|
409
|
-
if (!
|
|
410
|
-
const m = await
|
|
411
|
-
|
|
409
|
+
if (!_.ok) throw new Error("not found");
|
|
410
|
+
const m = await _.json();
|
|
411
|
+
a({
|
|
412
412
|
role: m.role.role_name,
|
|
413
413
|
userId: m.user_id,
|
|
414
414
|
userName: m.user_name,
|
|
415
|
-
privileges: m.role.privileges.map((
|
|
415
|
+
privileges: m.role.privileges.map((E) => E.privilege.trim())
|
|
416
416
|
});
|
|
417
417
|
} catch {
|
|
418
|
-
|
|
418
|
+
a(null);
|
|
419
419
|
}
|
|
420
|
-
|
|
420
|
+
i(!1);
|
|
421
421
|
}, []);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
}, [
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
}, [
|
|
428
|
-
|
|
429
|
-
}, [
|
|
430
|
-
return /* @__PURE__ */
|
|
431
|
-
},
|
|
432
|
-
const { authManager: r, loadMe: t } =
|
|
433
|
-
return
|
|
422
|
+
N(() => {
|
|
423
|
+
f();
|
|
424
|
+
}, [f]);
|
|
425
|
+
const d = j(() => {
|
|
426
|
+
C(t);
|
|
427
|
+
}, [C, t]), R = j(() => {
|
|
428
|
+
q(t), a(null);
|
|
429
|
+
}, [q, t]);
|
|
430
|
+
return /* @__PURE__ */ g.jsx($.Provider, { value: { loadMe: f, loading: s, user: o, login: d, authManager: t, logout: R }, children: r });
|
|
431
|
+
}, ke = () => {
|
|
432
|
+
const { authManager: r, loadMe: t } = H($);
|
|
433
|
+
return N(() => {
|
|
434
434
|
r && (z(r), t());
|
|
435
|
-
}, [z, r, t]), /* @__PURE__ */
|
|
435
|
+
}, [z, r, t]), /* @__PURE__ */ g.jsx("div", {});
|
|
436
436
|
}, U = () => {
|
|
437
|
-
const r =
|
|
437
|
+
const r = H($);
|
|
438
438
|
if (!r || !r.authManager) throw new Error("AuthContext not found");
|
|
439
439
|
return r;
|
|
440
|
-
},
|
|
440
|
+
}, Ee = (r) => {
|
|
441
441
|
const { user: t } = U();
|
|
442
442
|
return !!t?.privileges?.includes(r);
|
|
443
443
|
};
|
|
444
|
-
function
|
|
445
|
-
const { loading:
|
|
446
|
-
return
|
|
444
|
+
function Pe({ privilege: r, invalidPage: t, loadingPage: o }) {
|
|
445
|
+
const { loading: a } = U(), s = Ee(r);
|
|
446
|
+
return a ? o : s ? /* @__PURE__ */ g.jsx(X, {}) : t;
|
|
447
447
|
}
|
|
448
|
-
function
|
|
449
|
-
const { authManager: t, login: o, user:
|
|
450
|
-
return
|
|
448
|
+
function Ae({ loadingPage: r }) {
|
|
449
|
+
const { authManager: t, login: o, user: a } = U(), [s, i] = I(!0);
|
|
450
|
+
return N(() => {
|
|
451
451
|
if (!t) return;
|
|
452
|
-
t.getToken() ?
|
|
453
|
-
}, [t,
|
|
452
|
+
t.getToken() ? i(!1) : o();
|
|
453
|
+
}, [t, a]), t ? s ? r ?? /* @__PURE__ */ g.jsx("div", { children: "Loading..." }) : /* @__PURE__ */ g.jsx(X, {}) : /* @__PURE__ */ g.jsx("p", { children: "invalud config" });
|
|
454
454
|
}
|
|
455
455
|
export {
|
|
456
456
|
$ as AuthContext,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
457
|
+
Se as AuthManager,
|
|
458
|
+
we as AuthProvider,
|
|
459
|
+
ke as CallbackPage,
|
|
460
|
+
Re as Config,
|
|
461
|
+
Pe as PrivilegeGate,
|
|
462
|
+
Ae as ProtectGate,
|
|
463
|
+
Z as apiFetch,
|
|
464
464
|
z as handleCallback,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
465
|
+
C as login,
|
|
466
|
+
q as logout,
|
|
467
|
+
me as refreshToken,
|
|
468
468
|
U as useAuth,
|
|
469
|
-
|
|
469
|
+
Ee as usePrivilege
|
|
470
470
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(l,
|
|
1
|
+
(function(l,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-router-dom"],d):(l=typeof globalThis<"u"?globalThis:l||self,d(l["alex-evo-sh-auth"]={},l.React,l.ReactRouterDOM))})(this,(function(l,d,D){"use strict";async function J(t){const r=await fetch(`${t.authServer}/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",client_id:t.clientId})});if(r.status===401)return localStorage.removeItem(t.baseKey+"_access"),null;const o=await r.json();return localStorage.setItem(t.baseKey+"_access",o.access),o.access}class ${constructor(r,o){this.onAuthFail=o,this.config=r}refreshPromise=null;config;getToken(){return localStorage.getItem(this.config.baseKey+"_access")}setToken(r){r?localStorage.setItem(this.config.baseKey+"_access",r):localStorage.removeItem(this.config.baseKey+"_access")}async getValidToken(){let r=this.getToken();return r||(this.refreshPromise||(this.refreshPromise=J(this.config).then(o=>(this.setToken(o),o)).finally(()=>{this.refreshPromise=null})),r=await this.refreshPromise,!r&&this.onAuthFail&&this.onAuthFail(),r)}}class q{authServer;clientId;redirectUri;homePage;baseKey;constructor(r,o,s,a,c){this.authServer=r,this.clientId=o,this.redirectUri=s,this.homePage=a,this.baseKey=c}}async function O(t,r,o={},s){let a=t.getToken();const c=h=>fetch(r,{...o,headers:{...o.headers,Authorization:h?`Bearer ${h}`:""}});let m=await c(a);return m.status!==401?m:(t.setToken(null),a=await t.getValidToken(),a?c(a):(s?.(),m))}async function j(t){const r=new URLSearchParams(window.location.search),o=r.get("code"),s=sessionStorage.getItem("oauth_state"),a=r.get("state");if(!o)return;if(!a||a!==s)throw new Error("Invalid OAuth state");const c=sessionStorage.getItem("pkce_verifier"),h=await(await fetch(`${t.config.authServer}/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:t.config.clientId,code:o,code_verifier:c})})).json();localStorage.setItem(t.config.baseKey+"_access",h.access),window.history.replaceState({},document.title,t.config.homePage),window.location.href=t.config.homePage}function ee(t=64){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let o="";const s=new Uint8Array(t);crypto.getRandomValues(s);for(let a=0;a<s.length;a++)o+=r[s[a]%r.length];return o}async function te(t){const o=new TextEncoder().encode(t),s=await crypto.subtle.digest("SHA-256",o);return new Uint8Array(s)}function re(t){return btoa(String.fromCharCode(...Array.from(t))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function y(t){const r=ee(64),o=re(await te(r));sessionStorage.setItem("pkce_verifier",r);const s=crypto.randomUUID();sessionStorage.setItem("oauth_state",s);const a=new URLSearchParams({response_type:"code",client_id:t.config.clientId,redirect_uri:t.config.redirectUri,code_challenge:o,code_challenge_method:"S256",state:s});window.location.href=`${t.config.authServer}/authorize?${a}`}async function C(t){try{await O(t,`${t.config.authServer}/logout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:t.config.clientId})}),localStorage.removeItem(t.config.baseKey+"_access"),await y(t)}catch(r){console.error(r)}}const T=d.createContext({login:()=>{},logout:()=>{},loadMe:()=>{},authManager:null,user:null,loading:!1});var S={exports:{}},b={};var V;function ne(){if(V)return b;V=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function o(s,a,c){var m=null;if(c!==void 0&&(m=""+c),a.key!==void 0&&(m=""+a.key),"key"in a){c={};for(var h in a)h!=="key"&&(c[h]=a[h])}else c=a;return a=c.ref,{$$typeof:t,type:s,key:m,ref:a!==void 0?a:null,props:c}}return b.Fragment=r,b.jsx=o,b.jsxs=o,b}var p={};var W;function oe(){return W||(W=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Ee?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case I:return"Fragment";case de:return"Profiler";case fe:return"StrictMode";case _e:return"Suspense";case ve:return"SuspenseList";case pe:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case ue:return"Portal";case he:return e.displayName||"Context";case me:return(e._context.displayName||"Context")+".Consumer";case ge:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case be:return n=e.displayName||null,n!==null?n:t(e.type)||"Memo";case N:n=e._payload,e=e._init;try{return t(e(n))}catch{}}return null}function r(e){return""+e}function o(e){try{r(e);var n=!1}catch{n=!0}if(n){n=console;var i=n.error,u=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",u),r(e)}}function s(e){if(e===I)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===N)return"<...>";try{var n=t(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function a(){var e=F.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function m(e){if(B.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function h(e,n){function i(){H||(H=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",n))}i.isReactWarning=!0,Object.defineProperty(e,"key",{get:i,configurable:!0})}function x(){var e=t(this.type);return X[e]||(X[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function R(e,n,i,u,A,Y){var f=i.ref;return e={$$typeof:K,type:e,key:n,props:i,_owner:u},(f!==void 0?f:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:x}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:A}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function E(e,n,i,u,A,Y){var f=n.children;if(f!==void 0)if(u)if(ye(f)){for(u=0;u<f.length;u++)g(f[u]);Object.freeze&&Object.freeze(f)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else g(f);if(B.call(n,"key")){f=t(e);var v=Object.keys(n).filter(function(Te){return Te!=="key"});u=0<v.length?"{key: someKey, "+v.join(": ..., ")+": ...}":"{key: someKey}",Q[f+u]||(v=0<v.length?"{"+v.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,f,
|
|
6
|
+
<%s key={someKey} {...props} />`,u,f,v,f),Q[f+u]=!0)}if(f=null,i!==void 0&&(o(i),f=""+i),m(n)&&(o(n.key),f=""+n.key),"key"in n){i={};for(var L in n)L!=="key"&&(i[L]=n[L])}else i=n;return f&&h(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),R(e,f,i,a(),A,Y)}function g(e){w(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===N&&(e._payload.status==="fulfilled"?w(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function w(e){return typeof e=="object"&&e!==null&&e.$$typeof===K}var P=d,K=Symbol.for("react.transitional.element"),ue=Symbol.for("react.portal"),I=Symbol.for("react.fragment"),fe=Symbol.for("react.strict_mode"),de=Symbol.for("react.profiler"),me=Symbol.for("react.consumer"),he=Symbol.for("react.context"),ge=Symbol.for("react.forward_ref"),_e=Symbol.for("react.suspense"),ve=Symbol.for("react.suspense_list"),be=Symbol.for("react.memo"),N=Symbol.for("react.lazy"),pe=Symbol.for("react.activity"),Ee=Symbol.for("react.client.reference"),F=P.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=Object.prototype.hasOwnProperty,ye=Array.isArray,U=console.createTask?console.createTask:function(){return null};P={react_stack_bottom_frame:function(e){return e()}};var H,X={},M=P.react_stack_bottom_frame.bind(P,c)(),Z=U(s(c)),Q={};p.Fragment=I,p.jsx=function(e,n,i){var u=1e4>F.recentlyCreatedOwnerStacks++;return E(e,n,i,!1,u?Error("react-stack-top-frame"):M,u?U(s(e)):Z)},p.jsxs=function(e,n,i){var u=1e4>F.recentlyCreatedOwnerStacks++;return E(e,n,i,!0,u?Error("react-stack-top-frame"):M,u?U(s(e)):Z)}})()),p}var z;function ae(){return z||(z=1,process.env.NODE_ENV==="production"?S.exports=ne():S.exports=oe()),S.exports}var _=ae();const se=({children:t,authManager:r})=>{const[o,s]=d.useState(null),[a,c]=d.useState(!0),m=d.useCallback(async()=>{c(!0);const R=localStorage.getItem(r.config.baseKey+"_access");if(!R){s(null),c(!1);return}try{const E=await O(r,`${r.config.authServer}/me`,{headers:{Authorization:`Bearer ${R}`}});if(!E.ok)throw new Error("not found");const g=await E.json();s({role:g.role.role_name,userId:g.user_id,userName:g.user_name,privileges:g.role.privileges.map(w=>w.privilege.trim())})}catch{s(null)}c(!1)},[]);d.useEffect(()=>{m()},[m]);const h=d.useCallback(()=>{y(r)},[y,r]),x=d.useCallback(()=>{C(r),s(null)},[C,r]);return _.jsx(T.Provider,{value:{loadMe:m,loading:a,user:o,login:h,authManager:r,logout:x},children:t})},ce=()=>{const{authManager:t,loadMe:r}=d.useContext(T);return d.useEffect(()=>{t&&(j(t),r())},[j,t,r]),_.jsx("div",{})},k=()=>{const t=d.useContext(T);if(!t||!t.authManager)throw new Error("AuthContext not found");return t},G=t=>{const{user:r}=k();return!!r?.privileges?.includes(t)};function ie({privilege:t,invalidPage:r,loadingPage:o}){const{loading:s}=k(),a=G(t);return s?o:a?_.jsx(D.Outlet,{}):r}function le({loadingPage:t}){const{authManager:r,login:o,user:s}=k(),[a,c]=d.useState(!0);return d.useEffect(()=>{if(!r)return;r.getToken()?c(!1):o()},[r,s]),r?a?t??_.jsx("div",{children:"Loading..."}):_.jsx(D.Outlet,{}):_.jsx("p",{children:"invalud config"})}l.AuthContext=T,l.AuthManager=$,l.AuthProvider=se,l.CallbackPage=ce,l.Config=q,l.PrivilegeGate=ie,l.ProtectGate=le,l.apiFetch=O,l.handleCallback=j,l.login=y,l.logout=C,l.refreshToken=J,l.useAuth=k,l.usePrivilege=G,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthManager } from '../helpers/authManager';
|
|
2
2
|
type IAuthProvider = {
|
|
3
|
-
|
|
3
|
+
authManager: AuthManager;
|
|
4
4
|
children: React.ReactNode;
|
|
5
5
|
};
|
|
6
|
-
export declare const AuthProvider: ({ children,
|
|
6
|
+
export declare const AuthProvider: ({ children, authManager }: IAuthProvider) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|