alex-evo-sh-auth 0.0.12 → 0.0.14
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.
|
@@ -13,12 +13,12 @@ async function wr(n) {
|
|
|
13
13
|
});
|
|
14
14
|
if (a.status === 401)
|
|
15
15
|
return localStorage.removeItem(n.baseKey + "_access"), null;
|
|
16
|
-
const
|
|
17
|
-
return localStorage.setItem(n.baseKey + "_access",
|
|
16
|
+
const u = await a.json();
|
|
17
|
+
return localStorage.setItem(n.baseKey + "_access", u.access), u.access;
|
|
18
18
|
}
|
|
19
19
|
class Tr {
|
|
20
|
-
constructor(a,
|
|
21
|
-
this.onAuthFail =
|
|
20
|
+
constructor(a, u) {
|
|
21
|
+
this.onAuthFail = u, this.config = a;
|
|
22
22
|
}
|
|
23
23
|
refreshPromise = null;
|
|
24
24
|
config;
|
|
@@ -30,7 +30,7 @@ class Tr {
|
|
|
30
30
|
}
|
|
31
31
|
async getValidToken() {
|
|
32
32
|
let a = this.getToken();
|
|
33
|
-
return a || (this.refreshPromise || (this.refreshPromise = wr(this.config).then((
|
|
33
|
+
return a || (this.refreshPromise || (this.refreshPromise = wr(this.config).then((u) => (this.setToken(u), u)).finally(() => {
|
|
34
34
|
this.refreshPromise = null;
|
|
35
35
|
})), a = await this.refreshPromise, !a && this.onAuthFail && this.onAuthFail(), a);
|
|
36
36
|
}
|
|
@@ -41,68 +41,68 @@ class Dr {
|
|
|
41
41
|
redirectUri;
|
|
42
42
|
homePage;
|
|
43
43
|
baseKey;
|
|
44
|
-
constructor(a,
|
|
45
|
-
this.authServer = a, this.clientId =
|
|
44
|
+
constructor(a, u, c, d, p) {
|
|
45
|
+
this.authServer = a, this.clientId = u, this.redirectUri = c, this.homePage = d, this.baseKey = p;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
async function We(n, a,
|
|
49
|
-
let
|
|
50
|
-
const
|
|
51
|
-
...
|
|
48
|
+
async function We(n, a, u = {}, c) {
|
|
49
|
+
let d = n.getToken();
|
|
50
|
+
const p = (m) => fetch(a, {
|
|
51
|
+
...u,
|
|
52
52
|
headers: {
|
|
53
|
-
...
|
|
54
|
-
Authorization:
|
|
53
|
+
...u.headers,
|
|
54
|
+
Authorization: m ? `Bearer ${m}` : ""
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
|
-
let
|
|
58
|
-
return
|
|
57
|
+
let g = await p(d);
|
|
58
|
+
return g.status !== 401 ? g : (n.setToken(null), d = await n.getValidToken(), d ? p(d) : (c?.(), g));
|
|
59
59
|
}
|
|
60
60
|
async function je(n) {
|
|
61
|
-
const a = new URLSearchParams(window.location.search),
|
|
62
|
-
if (!
|
|
63
|
-
if (!d || d !==
|
|
61
|
+
const a = new URLSearchParams(window.location.search), u = a.get("code"), c = sessionStorage.getItem("oauth_state"), d = a.get("state");
|
|
62
|
+
if (!u) return;
|
|
63
|
+
if (!d || d !== c)
|
|
64
64
|
throw new Error("Invalid OAuth state");
|
|
65
|
-
const p = sessionStorage.getItem("pkce_verifier"),
|
|
65
|
+
const p = sessionStorage.getItem("pkce_verifier"), m = await (await fetch(`${n.config.authServer}/token`, {
|
|
66
66
|
method: "POST",
|
|
67
67
|
headers: {
|
|
68
68
|
"Content-Type": "application/json"
|
|
69
69
|
},
|
|
70
70
|
body: JSON.stringify({
|
|
71
71
|
client_id: n.config.clientId,
|
|
72
|
-
code:
|
|
72
|
+
code: u,
|
|
73
73
|
code_verifier: p
|
|
74
74
|
})
|
|
75
75
|
})).json();
|
|
76
|
-
localStorage.setItem(n.config.baseKey + "_access",
|
|
76
|
+
localStorage.setItem(n.config.baseKey + "_access", m.access), window.history.replaceState({}, document.title, n.config.homePage), window.location.href = n.config.homePage;
|
|
77
77
|
}
|
|
78
78
|
function Pr(n = 64) {
|
|
79
79
|
const a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
80
|
-
let
|
|
81
|
-
const
|
|
82
|
-
crypto.getRandomValues(
|
|
83
|
-
for (let d = 0; d <
|
|
84
|
-
|
|
85
|
-
return
|
|
80
|
+
let u = "";
|
|
81
|
+
const c = new Uint8Array(n);
|
|
82
|
+
crypto.getRandomValues(c);
|
|
83
|
+
for (let d = 0; d < c.length; d++)
|
|
84
|
+
u += a[c[d] % a.length];
|
|
85
|
+
return u;
|
|
86
86
|
}
|
|
87
87
|
async function Or(n) {
|
|
88
|
-
const
|
|
89
|
-
return new Uint8Array(
|
|
88
|
+
const u = new TextEncoder().encode(n), c = await crypto.subtle.digest("SHA-256", u);
|
|
89
|
+
return new Uint8Array(c);
|
|
90
90
|
}
|
|
91
91
|
function Cr(n) {
|
|
92
92
|
return btoa(String.fromCharCode(...Array.from(n))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
93
93
|
}
|
|
94
94
|
async function ee(n) {
|
|
95
|
-
const a = Pr(64),
|
|
95
|
+
const a = Pr(64), u = Cr(await Or(a));
|
|
96
96
|
sessionStorage.setItem("pkce_verifier", a);
|
|
97
|
-
const
|
|
98
|
-
sessionStorage.setItem("oauth_state",
|
|
97
|
+
const c = crypto.randomUUID();
|
|
98
|
+
sessionStorage.setItem("oauth_state", c);
|
|
99
99
|
const d = new URLSearchParams({
|
|
100
100
|
response_type: "code",
|
|
101
101
|
client_id: n.config.clientId,
|
|
102
102
|
redirect_uri: n.config.redirectUri,
|
|
103
|
-
code_challenge:
|
|
103
|
+
code_challenge: u,
|
|
104
104
|
code_challenge_method: "S256",
|
|
105
|
-
state:
|
|
105
|
+
state: c
|
|
106
106
|
});
|
|
107
107
|
window.location.href = `${n.config.authServer}/authorize?${d}`;
|
|
108
108
|
}
|
|
@@ -137,21 +137,21 @@ var Ae;
|
|
|
137
137
|
function kr() {
|
|
138
138
|
if (Ae) return U;
|
|
139
139
|
Ae = 1;
|
|
140
|
-
var n = De, a = /* @__PURE__ */ Symbol.for("react.element"),
|
|
141
|
-
function
|
|
142
|
-
var
|
|
140
|
+
var n = De, a = /* @__PURE__ */ Symbol.for("react.element"), u = /* @__PURE__ */ Symbol.for("react.fragment"), c = Object.prototype.hasOwnProperty, d = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
141
|
+
function g(m, y, P) {
|
|
142
|
+
var _, S = {}, w = null, j = null;
|
|
143
143
|
P !== void 0 && (w = "" + P), y.key !== void 0 && (w = "" + y.key), y.ref !== void 0 && (j = y.ref);
|
|
144
|
-
for (
|
|
145
|
-
if (
|
|
146
|
-
return { $$typeof: a, type:
|
|
144
|
+
for (_ in y) c.call(y, _) && !p.hasOwnProperty(_) && (S[_] = y[_]);
|
|
145
|
+
if (m && m.defaultProps) for (_ in y = m.defaultProps, y) S[_] === void 0 && (S[_] = y[_]);
|
|
146
|
+
return { $$typeof: a, type: m, key: w, ref: j, props: S, _owner: d.current };
|
|
147
147
|
}
|
|
148
|
-
return U.Fragment =
|
|
148
|
+
return U.Fragment = u, U.jsx = g, U.jsxs = g, U;
|
|
149
149
|
}
|
|
150
150
|
var W = {};
|
|
151
151
|
var Ie;
|
|
152
152
|
function jr() {
|
|
153
153
|
return Ie || (Ie = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
154
|
-
var n = De, a = /* @__PURE__ */ Symbol.for("react.element"),
|
|
154
|
+
var n = De, a = /* @__PURE__ */ Symbol.for("react.element"), u = /* @__PURE__ */ Symbol.for("react.portal"), c = /* @__PURE__ */ Symbol.for("react.fragment"), d = /* @__PURE__ */ Symbol.for("react.strict_mode"), p = /* @__PURE__ */ Symbol.for("react.profiler"), g = /* @__PURE__ */ Symbol.for("react.provider"), m = /* @__PURE__ */ Symbol.for("react.context"), y = /* @__PURE__ */ Symbol.for("react.forward_ref"), P = /* @__PURE__ */ Symbol.for("react.suspense"), _ = /* @__PURE__ */ Symbol.for("react.suspense_list"), S = /* @__PURE__ */ Symbol.for("react.memo"), w = /* @__PURE__ */ Symbol.for("react.lazy"), j = /* @__PURE__ */ Symbol.for("react.offscreen"), ae = Symbol.iterator, Ye = "@@iterator";
|
|
155
155
|
function Le(e) {
|
|
156
156
|
if (e === null || typeof e != "object")
|
|
157
157
|
return null;
|
|
@@ -159,7 +159,7 @@ function jr() {
|
|
|
159
159
|
return typeof r == "function" ? r : null;
|
|
160
160
|
}
|
|
161
161
|
var x = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
162
|
-
function
|
|
162
|
+
function b(e) {
|
|
163
163
|
{
|
|
164
164
|
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), o = 1; o < r; o++)
|
|
165
165
|
t[o - 1] = arguments[o];
|
|
@@ -179,7 +179,7 @@ function jr() {
|
|
|
179
179
|
var Ke = !1, Ne = !1, Je = !1, Me = !1, Be = !1, oe;
|
|
180
180
|
oe = /* @__PURE__ */ Symbol.for("react.module.reference");
|
|
181
181
|
function qe(e) {
|
|
182
|
-
return !!(typeof e == "string" || typeof e == "function" || e ===
|
|
182
|
+
return !!(typeof e == "string" || typeof e == "function" || e === c || e === p || Be || e === d || e === P || e === _ || Me || e === j || Ke || Ne || Je || typeof e == "object" && e !== null && (e.$$typeof === w || e.$$typeof === S || e.$$typeof === g || e.$$typeof === m || e.$$typeof === y || // This needs to include all possible module reference object
|
|
183
183
|
// types supported by any Flight configuration anywhere since
|
|
184
184
|
// we don't know which Flight build this will end up being used
|
|
185
185
|
// with.
|
|
@@ -198,14 +198,14 @@ function jr() {
|
|
|
198
198
|
function O(e) {
|
|
199
199
|
if (e == null)
|
|
200
200
|
return null;
|
|
201
|
-
if (typeof e.tag == "number" &&
|
|
201
|
+
if (typeof e.tag == "number" && b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
|
|
202
202
|
return e.displayName || e.name || null;
|
|
203
203
|
if (typeof e == "string")
|
|
204
204
|
return e;
|
|
205
205
|
switch (e) {
|
|
206
|
-
case u:
|
|
207
|
-
return "Fragment";
|
|
208
206
|
case c:
|
|
207
|
+
return "Fragment";
|
|
208
|
+
case u:
|
|
209
209
|
return "Portal";
|
|
210
210
|
case p:
|
|
211
211
|
return "Profiler";
|
|
@@ -213,15 +213,15 @@ function jr() {
|
|
|
213
213
|
return "StrictMode";
|
|
214
214
|
case P:
|
|
215
215
|
return "Suspense";
|
|
216
|
-
case
|
|
216
|
+
case _:
|
|
217
217
|
return "SuspenseList";
|
|
218
218
|
}
|
|
219
219
|
if (typeof e == "object")
|
|
220
220
|
switch (e.$$typeof) {
|
|
221
|
-
case
|
|
221
|
+
case m:
|
|
222
222
|
var r = e;
|
|
223
223
|
return ie(r) + ".Consumer";
|
|
224
|
-
case
|
|
224
|
+
case g:
|
|
225
225
|
var t = e;
|
|
226
226
|
return ie(t._context) + ".Provider";
|
|
227
227
|
case y:
|
|
@@ -299,7 +299,7 @@ function jr() {
|
|
|
299
299
|
})
|
|
300
300
|
});
|
|
301
301
|
}
|
|
302
|
-
D < 0 &&
|
|
302
|
+
D < 0 && b("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
var J = x.ReactCurrentDispatcher, M;
|
|
@@ -347,42 +347,42 @@ function jr() {
|
|
|
347
347
|
}), typeof Reflect == "object" && Reflect.construct) {
|
|
348
348
|
try {
|
|
349
349
|
Reflect.construct(s, []);
|
|
350
|
-
} catch (
|
|
351
|
-
o =
|
|
350
|
+
} catch (R) {
|
|
351
|
+
o = R;
|
|
352
352
|
}
|
|
353
353
|
Reflect.construct(e, [], s);
|
|
354
354
|
} else {
|
|
355
355
|
try {
|
|
356
356
|
s.call();
|
|
357
|
-
} catch (
|
|
358
|
-
o =
|
|
357
|
+
} catch (R) {
|
|
358
|
+
o = R;
|
|
359
359
|
}
|
|
360
360
|
e.call(s.prototype);
|
|
361
361
|
}
|
|
362
362
|
} else {
|
|
363
363
|
try {
|
|
364
364
|
throw Error();
|
|
365
|
-
} catch (
|
|
366
|
-
o =
|
|
365
|
+
} catch (R) {
|
|
366
|
+
o = R;
|
|
367
367
|
}
|
|
368
368
|
e();
|
|
369
369
|
}
|
|
370
|
-
} catch (
|
|
371
|
-
if (
|
|
372
|
-
for (var i =
|
|
373
|
-
`),
|
|
374
|
-
`), v = i.length - 1,
|
|
375
|
-
|
|
376
|
-
for (; v >= 1 &&
|
|
377
|
-
if (i[v] !==
|
|
378
|
-
if (v !== 1 ||
|
|
370
|
+
} catch (R) {
|
|
371
|
+
if (R && o && typeof R.stack == "string") {
|
|
372
|
+
for (var i = R.stack.split(`
|
|
373
|
+
`), E = o.stack.split(`
|
|
374
|
+
`), v = i.length - 1, h = E.length - 1; v >= 1 && h >= 0 && i[v] !== E[h]; )
|
|
375
|
+
h--;
|
|
376
|
+
for (; v >= 1 && h >= 0; v--, h--)
|
|
377
|
+
if (i[v] !== E[h]) {
|
|
378
|
+
if (v !== 1 || h !== 1)
|
|
379
379
|
do
|
|
380
|
-
if (v--,
|
|
380
|
+
if (v--, h--, h < 0 || i[v] !== E[h]) {
|
|
381
381
|
var T = `
|
|
382
382
|
` + i[v].replace(" at new ", " at ");
|
|
383
383
|
return e.displayName && T.includes("<anonymous>") && (T = T.replace("<anonymous>", e.displayName)), typeof e == "function" && L.set(e, T), T;
|
|
384
384
|
}
|
|
385
|
-
while (v >= 1 &&
|
|
385
|
+
while (v >= 1 && h >= 0);
|
|
386
386
|
break;
|
|
387
387
|
}
|
|
388
388
|
}
|
|
@@ -409,7 +409,7 @@ function jr() {
|
|
|
409
409
|
switch (e) {
|
|
410
410
|
case P:
|
|
411
411
|
return Y("Suspense");
|
|
412
|
-
case
|
|
412
|
+
case _:
|
|
413
413
|
return Y("SuspenseList");
|
|
414
414
|
}
|
|
415
415
|
if (typeof e == "object")
|
|
@@ -444,14 +444,14 @@ function jr() {
|
|
|
444
444
|
var i = void 0;
|
|
445
445
|
try {
|
|
446
446
|
if (typeof e[s] != "function") {
|
|
447
|
-
var
|
|
448
|
-
throw
|
|
447
|
+
var E = Error((o || "React class") + ": " + t + " type `" + s + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[s] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
|
|
448
|
+
throw E.name = "Invariant Violation", E;
|
|
449
449
|
}
|
|
450
450
|
i = e[s](r, s, o, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
|
|
451
451
|
} catch (v) {
|
|
452
452
|
i = v;
|
|
453
453
|
}
|
|
454
|
-
i && !(i instanceof Error) && (K(l),
|
|
454
|
+
i && !(i instanceof Error) && (K(l), b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", o || "React class", t, s, typeof i), K(null)), i instanceof Error && !(i.message in pe) && (pe[i.message] = !0, K(l), b("Failed %s type: %s", t, i.message), K(null));
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
}
|
|
@@ -477,7 +477,7 @@ function jr() {
|
|
|
477
477
|
}
|
|
478
478
|
function _e(e) {
|
|
479
479
|
if (nr(e))
|
|
480
|
-
return
|
|
480
|
+
return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", tr(e)), me(e);
|
|
481
481
|
}
|
|
482
482
|
var be = x.ReactCurrentOwner, ar = {
|
|
483
483
|
key: !0,
|
|
@@ -507,7 +507,7 @@ function jr() {
|
|
|
507
507
|
function ur(e, r) {
|
|
508
508
|
{
|
|
509
509
|
var t = function() {
|
|
510
|
-
Ee || (Ee = !0,
|
|
510
|
+
Ee || (Ee = !0, b("%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://reactjs.org/link/special-props)", r));
|
|
511
511
|
};
|
|
512
512
|
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
513
513
|
get: t,
|
|
@@ -518,7 +518,7 @@ function jr() {
|
|
|
518
518
|
function cr(e, r) {
|
|
519
519
|
{
|
|
520
520
|
var t = function() {
|
|
521
|
-
Re || (Re = !0,
|
|
521
|
+
Re || (Re = !0, b("%s: `ref` 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://reactjs.org/link/special-props)", r));
|
|
522
522
|
};
|
|
523
523
|
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
|
|
524
524
|
get: t,
|
|
@@ -557,8 +557,8 @@ function jr() {
|
|
|
557
557
|
};
|
|
558
558
|
function fr(e, r, t, o, l) {
|
|
559
559
|
{
|
|
560
|
-
var f, s = {}, i = null,
|
|
561
|
-
t !== void 0 && (_e(t), i = "" + t), ir(r) && (_e(r.key), i = "" + r.key), or(r) && (
|
|
560
|
+
var f, s = {}, i = null, E = null;
|
|
561
|
+
t !== void 0 && (_e(t), i = "" + t), ir(r) && (_e(r.key), i = "" + r.key), or(r) && (E = r.ref, sr(r, l));
|
|
562
562
|
for (f in r)
|
|
563
563
|
$.call(r, f) && !ar.hasOwnProperty(f) && (s[f] = r[f]);
|
|
564
564
|
if (e && e.defaultProps) {
|
|
@@ -566,11 +566,11 @@ function jr() {
|
|
|
566
566
|
for (f in v)
|
|
567
567
|
s[f] === void 0 && (s[f] = v[f]);
|
|
568
568
|
}
|
|
569
|
-
if (i ||
|
|
570
|
-
var
|
|
571
|
-
i && ur(s,
|
|
569
|
+
if (i || E) {
|
|
570
|
+
var h = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
|
|
571
|
+
i && ur(s, h), E && cr(s, h);
|
|
572
572
|
}
|
|
573
|
-
return lr(e, i,
|
|
573
|
+
return lr(e, i, E, l, o, be.current, s);
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
var z = x.ReactCurrentOwner, Se = x.ReactDebugCurrentFrame;
|
|
@@ -624,7 +624,7 @@ Check the top-level render call using <` + t + ">.");
|
|
|
624
624
|
return;
|
|
625
625
|
Te[t] = !0;
|
|
626
626
|
var o = "";
|
|
627
|
-
e && e._owner && e._owner !== z.current && (o = " It was passed a child from " + O(e._owner.type) + "."), A(e),
|
|
627
|
+
e && e._owner && e._owner !== z.current && (o = " It was passed a child from " + O(e._owner.type) + "."), A(e), b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, o), A(null);
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
function Oe(e, r) {
|
|
@@ -666,9 +666,9 @@ Check the top-level render call using <` + t + ">.");
|
|
|
666
666
|
} else if (r.PropTypes !== void 0 && !G) {
|
|
667
667
|
G = !0;
|
|
668
668
|
var l = O(r);
|
|
669
|
-
|
|
669
|
+
b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", l || "Unknown");
|
|
670
670
|
}
|
|
671
|
-
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved &&
|
|
671
|
+
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
function hr(e) {
|
|
@@ -676,11 +676,11 @@ Check the top-level render call using <` + t + ">.");
|
|
|
676
676
|
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
|
|
677
677
|
var o = r[t];
|
|
678
678
|
if (o !== "children" && o !== "key") {
|
|
679
|
-
A(e),
|
|
679
|
+
A(e), b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", o), A(null);
|
|
680
680
|
break;
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
|
-
e.ref !== null && (A(e),
|
|
683
|
+
e.ref !== null && (A(e), b("Invalid attribute `ref` supplied to `React.Fragment`."), A(null));
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
686
|
var Ce = {};
|
|
@@ -690,14 +690,14 @@ Check the top-level render call using <` + t + ">.");
|
|
|
690
690
|
if (!s) {
|
|
691
691
|
var i = "";
|
|
692
692
|
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
|
|
693
|
-
var
|
|
694
|
-
|
|
693
|
+
var E = dr();
|
|
694
|
+
E ? i += E : i += we();
|
|
695
695
|
var v;
|
|
696
|
-
e === null ? v = "null" : q(e) ? v = "array" : e !== void 0 && e.$$typeof === a ? (v = "<" + (O(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : v = typeof e,
|
|
696
|
+
e === null ? v = "null" : q(e) ? v = "array" : e !== void 0 && e.$$typeof === a ? (v = "<" + (O(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : v = typeof e, b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", v, i);
|
|
697
697
|
}
|
|
698
|
-
var
|
|
699
|
-
if (
|
|
700
|
-
return
|
|
698
|
+
var h = fr(e, r, t, l, f);
|
|
699
|
+
if (h == null)
|
|
700
|
+
return h;
|
|
701
701
|
if (s) {
|
|
702
702
|
var T = r.children;
|
|
703
703
|
if (T !== void 0)
|
|
@@ -707,17 +707,17 @@ Check the top-level render call using <` + t + ">.");
|
|
|
707
707
|
Oe(T[I], e);
|
|
708
708
|
Object.freeze && Object.freeze(T);
|
|
709
709
|
} else
|
|
710
|
-
|
|
710
|
+
b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
|
|
711
711
|
else
|
|
712
712
|
Oe(T, e);
|
|
713
713
|
}
|
|
714
714
|
if ($.call(r, "key")) {
|
|
715
|
-
var k = O(e),
|
|
715
|
+
var k = O(e), R = Object.keys(r).filter(function(Er) {
|
|
716
716
|
return Er !== "key";
|
|
717
|
-
}), X =
|
|
717
|
+
}), X = R.length > 0 ? "{key: someKey, " + R.join(": ..., ") + ": ...}" : "{key: someKey}";
|
|
718
718
|
if (!Ce[k + X]) {
|
|
719
|
-
var br =
|
|
720
|
-
|
|
719
|
+
var br = R.length > 0 ? "{" + R.join(": ..., ") + ": ...}" : "{}";
|
|
720
|
+
b(`A props object containing a "key" prop is being spread into JSX:
|
|
721
721
|
let props = %s;
|
|
722
722
|
<%s {...props} />
|
|
723
723
|
React keys must be passed directly to JSX without using spread:
|
|
@@ -725,7 +725,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
725
725
|
<%s key={someKey} {...props} />`, X, k, br, k), Ce[k + X] = !0;
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
|
-
return e ===
|
|
728
|
+
return e === c ? hr(h) : gr(h), h;
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
731
|
function pr(e, r, t) {
|
|
@@ -735,7 +735,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
735
735
|
return ke(e, r, t, !1);
|
|
736
736
|
}
|
|
737
737
|
var mr = yr, _r = pr;
|
|
738
|
-
W.Fragment =
|
|
738
|
+
W.Fragment = c, W.jsx = mr, W.jsxs = _r;
|
|
739
739
|
})()), W;
|
|
740
740
|
}
|
|
741
741
|
var Fe;
|
|
@@ -744,41 +744,41 @@ function xr() {
|
|
|
744
744
|
}
|
|
745
745
|
var F = xr();
|
|
746
746
|
const $r = ({ children: n, authConfig: a }) => {
|
|
747
|
-
const [
|
|
747
|
+
const [u, c] = Q(null), [d, p] = Q(!0), g = Sr(() => new Tr(a), [a]), m = Z(async () => {
|
|
748
748
|
p(!0);
|
|
749
|
-
const
|
|
750
|
-
if (!
|
|
751
|
-
|
|
749
|
+
const _ = localStorage.getItem(g.config.baseKey + "_access");
|
|
750
|
+
if (!_) {
|
|
751
|
+
c(null), p(!1);
|
|
752
752
|
return;
|
|
753
753
|
}
|
|
754
754
|
try {
|
|
755
|
-
const S = await We(
|
|
755
|
+
const S = await We(g, `${g.config.authServer}/me`, {
|
|
756
756
|
headers: {
|
|
757
|
-
Authorization: `Bearer ${
|
|
757
|
+
Authorization: `Bearer ${_}`
|
|
758
758
|
}
|
|
759
759
|
});
|
|
760
760
|
if (!S.ok) throw new Error("not found");
|
|
761
761
|
const w = await S.json();
|
|
762
|
-
|
|
762
|
+
c({
|
|
763
763
|
role: w.role.role_name,
|
|
764
764
|
userId: w.user_id,
|
|
765
765
|
userName: w.user_name,
|
|
766
766
|
privileges: w.role.privileges.map((j) => j.privilege.trim())
|
|
767
767
|
});
|
|
768
768
|
} catch {
|
|
769
|
-
|
|
769
|
+
c(null);
|
|
770
770
|
}
|
|
771
771
|
p(!1);
|
|
772
772
|
}, []);
|
|
773
773
|
re(() => {
|
|
774
|
-
|
|
775
|
-
}, [
|
|
774
|
+
m();
|
|
775
|
+
}, [m]);
|
|
776
776
|
const y = Z(() => {
|
|
777
|
-
ee(
|
|
778
|
-
}, [ee,
|
|
779
|
-
xe(
|
|
780
|
-
}, [xe,
|
|
781
|
-
return /* @__PURE__ */ F.jsx(te.Provider, { value: { loadMe:
|
|
777
|
+
ee(g);
|
|
778
|
+
}, [ee, g]), P = Z(() => {
|
|
779
|
+
xe(g), c(null);
|
|
780
|
+
}, [xe, g]);
|
|
781
|
+
return /* @__PURE__ */ F.jsx(te.Provider, { value: { loadMe: m, loading: d, user: u, login: y, authManager: g, logout: P }, children: n });
|
|
782
782
|
}, Ur = () => {
|
|
783
783
|
const { authManager: n, loadMe: a } = $e(te);
|
|
784
784
|
return re(() => {
|
|
@@ -792,16 +792,16 @@ const $r = ({ children: n, authConfig: a }) => {
|
|
|
792
792
|
const { user: a } = ne();
|
|
793
793
|
return !!a?.privileges?.includes(n);
|
|
794
794
|
};
|
|
795
|
-
function Wr({ privilege: n, invalidPage: a, loadingPage:
|
|
796
|
-
const { loading:
|
|
797
|
-
return
|
|
795
|
+
function Wr({ privilege: n, invalidPage: a, loadingPage: u }) {
|
|
796
|
+
const { loading: c } = ne(), d = Ar(n);
|
|
797
|
+
return c ? u : d ? /* @__PURE__ */ F.jsx(Ue, {}) : a;
|
|
798
798
|
}
|
|
799
799
|
function Yr({ loadingPage: n }) {
|
|
800
|
-
const { authManager: a, login:
|
|
800
|
+
const { authManager: a, login: u, user: c } = ne(), [d, p] = Q(!0);
|
|
801
801
|
return re(() => {
|
|
802
802
|
if (!a) return;
|
|
803
|
-
a.getToken() ? p(!1) :
|
|
804
|
-
}, [a,
|
|
803
|
+
a.getToken() ? p(!1) : u();
|
|
804
|
+
}, [a, c]), a ? d ? n ?? /* @__PURE__ */ F.jsx("div", { children: "Loading..." }) : /* @__PURE__ */ F.jsx(Ue, {}) : /* @__PURE__ */ F.jsx("p", { children: "invalud config" });
|
|
805
805
|
}
|
|
806
806
|
export {
|
|
807
807
|
te as AuthContext,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
(function(v,
|
|
2
|
-
`+q+e}}var ee=!1,G;{var cr=typeof WeakMap=="function"?WeakMap:Map;G=new cr}function we(e,r){if(!e||ee)return"";{var t=G.get(e);if(t!==void 0)return t}var o;ee=!0;var l=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var f;f=Q.current,Q.current=null,ir();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(
|
|
3
|
-
`),
|
|
4
|
-
`),h=i.length-1,
|
|
5
|
-
`+i[h].replace(" at new "," at ");return e.displayName&&O.includes("<anonymous>")&&(O=O.replace("<anonymous>",e.displayName)),typeof e=="function"&&G.set(e,O),O}while(h>=1&&
|
|
1
|
+
(function(v,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-router-dom"],y):(v=typeof globalThis<"u"?globalThis:v||self,y(v["alex-evo-sh-auth"]={},v.React,v.ReactRouterDOM))})(this,(function(v,y,ie){"use strict";async function se(n){const a=await fetch(`${n.authServer}/refresh`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({grant_type:"refresh_token",client_id:n.clientId})});if(a.status===401)return localStorage.removeItem(n.baseKey+"_access"),null;const c=await a.json();return localStorage.setItem(n.baseKey+"_access",c.access),c.access}class ce{constructor(a,c){this.onAuthFail=c,this.config=a}refreshPromise=null;config;getToken(){return localStorage.getItem(this.config.baseKey+"_access")}setToken(a){a?localStorage.setItem(this.config.baseKey+"_access",a):localStorage.removeItem(this.config.baseKey+"_access")}async getValidToken(){let a=this.getToken();return a||(this.refreshPromise||(this.refreshPromise=se(this.config).then(c=>(this.setToken(c),c)).finally(()=>{this.refreshPromise=null})),a=await this.refreshPromise,!a&&this.onAuthFail&&this.onAuthFail(),a)}}class Le{authServer;clientId;redirectUri;homePage;baseKey;constructor(a,c,u,d,m){this.authServer=a,this.clientId=c,this.redirectUri=u,this.homePage=d,this.baseKey=m}}async function X(n,a,c={},u){let d=n.getToken();const m=b=>fetch(a,{...c,headers:{...c.headers,Authorization:b?`Bearer ${b}`:""}});let g=await m(d);return g.status!==401?g:(n.setToken(null),d=await n.getValidToken(),d?m(d):(u?.(),g))}async function $(n){const a=new URLSearchParams(window.location.search),c=a.get("code"),u=sessionStorage.getItem("oauth_state"),d=a.get("state");if(!c)return;if(!d||d!==u)throw new Error("Invalid OAuth state");const m=sessionStorage.getItem("pkce_verifier"),b=await(await fetch(`${n.config.authServer}/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:n.config.clientId,code:c,code_verifier:m})})).json();localStorage.setItem(n.config.baseKey+"_access",b.access),window.history.replaceState({},document.title,n.config.homePage),window.location.href=n.config.homePage}function Ve(n=64){const a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let c="";const u=new Uint8Array(n);crypto.getRandomValues(u);for(let d=0;d<u.length;d++)c+=a[u[d]%a.length];return c}async function Ke(n){const c=new TextEncoder().encode(n),u=await crypto.subtle.digest("SHA-256",c);return new Uint8Array(u)}function Me(n){return btoa(String.fromCharCode(...Array.from(n))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function K(n){const a=Ve(64),c=Me(await Ke(a));sessionStorage.setItem("pkce_verifier",a);const u=crypto.randomUUID();sessionStorage.setItem("oauth_state",u);const d=new URLSearchParams({response_type:"code",client_id:n.config.clientId,redirect_uri:n.config.redirectUri,code_challenge:c,code_challenge_method:"S256",state:u});window.location.href=`${n.config.authServer}/authorize?${d}`}async function Z(n){try{await X(n,`${n.config.authServer}/logout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:n.config.clientId})}),localStorage.removeItem(n.config.baseKey+"_access"),await K(n)}catch(a){console.error(a)}}const M=y.createContext({login:()=>{},logout:()=>{},loadMe:()=>{},authManager:null,user:null,loading:!1});var N={exports:{}},W={};var ue;function Ne(){if(ue)return W;ue=1;var n=y,a=Symbol.for("react.element"),c=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,d=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,m={key:!0,ref:!0,__self:!0,__source:!0};function g(b,_,C){var E,T={},P=null,I=null;C!==void 0&&(P=""+C),_.key!==void 0&&(P=""+_.key),_.ref!==void 0&&(I=_.ref);for(E in _)u.call(_,E)&&!m.hasOwnProperty(E)&&(T[E]=_[E]);if(b&&b.defaultProps)for(E in _=b.defaultProps,_)T[E]===void 0&&(T[E]=_[E]);return{$$typeof:a,type:b,key:P,ref:I,props:T,_owner:d.current}}return W.Fragment=c,W.jsx=g,W.jsxs=g,W}var Y={};var le;function Je(){return le||(le=1,process.env.NODE_ENV!=="production"&&(function(){var n=y,a=Symbol.for("react.element"),c=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),m=Symbol.for("react.profiler"),g=Symbol.for("react.provider"),b=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),P=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),ve=Symbol.iterator,$e="@@iterator";function Ze(e){if(e===null||typeof e!="object")return null;var r=ve&&e[ve]||e[$e];return typeof r=="function"?r:null}var F=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function R(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];Qe("error",e,t)}}function Qe(e,r,t){{var o=F.ReactDebugCurrentFrame,l=o.getStackAddendum();l!==""&&(r+="%s",t=t.concat([l]));var f=t.map(function(s){return String(s)});f.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,f)}}var qe=!1,er=!1,rr=!1,tr=!1,nr=!1,he;he=Symbol.for("react.module.reference");function ar(e){return!!(typeof e=="string"||typeof e=="function"||e===u||e===m||nr||e===d||e===C||e===E||tr||e===I||qe||er||rr||typeof e=="object"&&e!==null&&(e.$$typeof===P||e.$$typeof===T||e.$$typeof===g||e.$$typeof===b||e.$$typeof===_||e.$$typeof===he||e.getModuleId!==void 0))}function or(e,r,t){var o=e.displayName;if(o)return o;var l=r.displayName||r.name||"";return l!==""?t+"("+l+")":t}function ge(e){return e.displayName||"Context"}function k(e){if(e==null)return null;if(typeof e.tag=="number"&&R("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case c:return"Portal";case m:return"Profiler";case d:return"StrictMode";case C:return"Suspense";case E:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case b:var r=e;return ge(r)+".Consumer";case g:var t=e;return ge(t._context)+".Provider";case _:return or(e,e.render,"ForwardRef");case T:var o=e.displayName||null;return o!==null?o:k(e.type)||"Memo";case P:{var l=e,f=l._payload,s=l._init;try{return k(s(f))}catch{return null}}}return null}var j=Object.assign,L=0,pe,ye,me,_e,be,Ee,Re;function Se(){}Se.__reactDisabledLog=!0;function ir(){{if(L===0){pe=console.log,ye=console.info,me=console.warn,_e=console.error,be=console.group,Ee=console.groupCollapsed,Re=console.groupEnd;var e={configurable:!0,enumerable:!0,value:Se,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function sr(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:j({},e,{value:pe}),info:j({},e,{value:ye}),warn:j({},e,{value:me}),error:j({},e,{value:_e}),group:j({},e,{value:be}),groupCollapsed:j({},e,{value:Ee}),groupEnd:j({},e,{value:Re})})}L<0&&R("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Q=F.ReactCurrentDispatcher,q;function B(e,r,t){{if(q===void 0)try{throw Error()}catch(l){var o=l.stack.trim().match(/\n( *(at )?)/);q=o&&o[1]||""}return`
|
|
2
|
+
`+q+e}}var ee=!1,G;{var cr=typeof WeakMap=="function"?WeakMap:Map;G=new cr}function we(e,r){if(!e||ee)return"";{var t=G.get(e);if(t!==void 0)return t}var o;ee=!0;var l=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var f;f=Q.current,Q.current=null,ir();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(w){o=w}Reflect.construct(e,[],s)}else{try{s.call()}catch(w){o=w}e.call(s.prototype)}}else{try{throw Error()}catch(w){o=w}e()}}catch(w){if(w&&o&&typeof w.stack=="string"){for(var i=w.stack.split(`
|
|
3
|
+
`),S=o.stack.split(`
|
|
4
|
+
`),h=i.length-1,p=S.length-1;h>=1&&p>=0&&i[h]!==S[p];)p--;for(;h>=1&&p>=0;h--,p--)if(i[h]!==S[p]){if(h!==1||p!==1)do if(h--,p--,p<0||i[h]!==S[p]){var O=`
|
|
5
|
+
`+i[h].replace(" at new "," at ");return e.displayName&&O.includes("<anonymous>")&&(O=O.replace("<anonymous>",e.displayName)),typeof e=="function"&&G.set(e,O),O}while(h>=1&&p>=0);break}}}finally{ee=!1,Q.current=f,sr(),Error.prepareStackTrace=l}var U=e?e.displayName||e.name:"",x=U?B(U):"";return typeof e=="function"&&G.set(e,x),x}function ur(e,r,t){return we(e,!1)}function lr(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function z(e,r,t){if(e==null)return"";if(typeof e=="function")return we(e,lr(e));if(typeof e=="string")return B(e);switch(e){case C:return B("Suspense");case E:return B("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case _:return ur(e.render);case T:return z(e.type,r,t);case P:{var o=e,l=o._payload,f=o._init;try{return z(f(l),r,t)}catch{}}}return""}var V=Object.prototype.hasOwnProperty,Te={},Pe=F.ReactDebugCurrentFrame;function H(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);Pe.setExtraStackFrame(t)}else Pe.setExtraStackFrame(null)}function fr(e,r,t,o,l){{var f=Function.call.bind(V);for(var s in e)if(f(e,s)){var i=void 0;try{if(typeof e[s]!="function"){var S=Error((o||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw S.name="Invariant Violation",S}i=e[s](r,s,o,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(h){i=h}i&&!(i instanceof Error)&&(H(l),R("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",o||"React class",t,s,typeof i),H(null)),i instanceof Error&&!(i.message in Te)&&(Te[i.message]=!0,H(l),R("Failed %s type: %s",t,i.message),H(null))}}}var dr=Array.isArray;function re(e){return dr(e)}function vr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function hr(e){try{return Oe(e),!1}catch{return!0}}function Oe(e){return""+e}function Ce(e){if(hr(e))return R("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",vr(e)),Oe(e)}var ke=F.ReactCurrentOwner,gr={key:!0,ref:!0,__self:!0,__source:!0},je,xe;function pr(e){if(V.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function yr(e){if(V.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function mr(e,r){typeof e.ref=="string"&&ke.current}function _r(e,r){{var t=function(){je||(je=!0,R("%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://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function br(e,r){{var t=function(){xe||(xe=!0,R("%s: `ref` 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://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var Er=function(e,r,t,o,l,f,s){var i={$$typeof:a,type:e,key:r,ref:t,props:s,_owner:f};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:l}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function Rr(e,r,t,o,l){{var f,s={},i=null,S=null;t!==void 0&&(Ce(t),i=""+t),yr(r)&&(Ce(r.key),i=""+r.key),pr(r)&&(S=r.ref,mr(r,l));for(f in r)V.call(r,f)&&!gr.hasOwnProperty(f)&&(s[f]=r[f]);if(e&&e.defaultProps){var h=e.defaultProps;for(f in h)s[f]===void 0&&(s[f]=h[f])}if(i||S){var p=typeof e=="function"?e.displayName||e.name||"Unknown":e;i&&_r(s,p),S&&br(s,p)}return Er(e,i,S,l,o,ke.current,s)}}var te=F.ReactCurrentOwner,Ae=F.ReactDebugCurrentFrame;function D(e){if(e){var r=e._owner,t=z(e.type,e._source,r?r.type:null);Ae.setExtraStackFrame(t)}else Ae.setExtraStackFrame(null)}var ne;ne=!1;function ae(e){return typeof e=="object"&&e!==null&&e.$$typeof===a}function Ie(){{if(te.current){var e=k(te.current.type);if(e)return`
|
|
6
6
|
|
|
7
7
|
Check the render method of \``+e+"`."}return""}}function Sr(e){return""}var Fe={};function wr(e){{var r=Ie();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
|
|
8
8
|
|
|
9
|
-
Check the top-level render call using <`+t+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=wr(r);if(Fe[t])return;Fe[t]=!0;var o="";e&&e._owner&&e._owner!==te.current&&(o=" It was passed a child from "+k(e._owner.type)+"."),D(e),
|
|
9
|
+
Check the top-level render call using <`+t+">.")}return r}}function De(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=wr(r);if(Fe[t])return;Fe[t]=!0;var o="";e&&e._owner&&e._owner!==te.current&&(o=" It was passed a child from "+k(e._owner.type)+"."),D(e),R('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,o),D(null)}}function Ue(e,r){{if(typeof e!="object")return;if(re(e))for(var t=0;t<e.length;t++){var o=e[t];ae(o)&&De(o,r)}else if(ae(e))e._store&&(e._store.validated=!0);else if(e){var l=Ze(e);if(typeof l=="function"&&l!==e.entries)for(var f=l.call(e),s;!(s=f.next()).done;)ae(s.value)&&De(s.value,r)}}}function Tr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===_||r.$$typeof===T))t=r.propTypes;else return;if(t){var o=k(r);fr(t,e.props,"prop",o,e)}else if(r.PropTypes!==void 0&&!ne){ne=!0;var l=k(r);R("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",l||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&R("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Pr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var o=r[t];if(o!=="children"&&o!=="key"){D(e),R("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",o),D(null);break}}e.ref!==null&&(D(e),R("Invalid attribute `ref` supplied to `React.Fragment`."),D(null))}}var We={};function Ye(e,r,t,o,l,f){{var s=ar(e);if(!s){var i="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(i+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var S=Sr();S?i+=S:i+=Ie();var h;e===null?h="null":re(e)?h="array":e!==void 0&&e.$$typeof===a?(h="<"+(k(e.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):h=typeof e,R("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",h,i)}var p=Rr(e,r,t,l,f);if(p==null)return p;if(s){var O=r.children;if(O!==void 0)if(o)if(re(O)){for(var U=0;U<O.length;U++)Ue(O[U],e);Object.freeze&&Object.freeze(O)}else R("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 Ue(O,e)}if(V.call(r,"key")){var x=k(e),w=Object.keys(r).filter(function(Ar){return Ar!=="key"}),oe=w.length>0?"{key: someKey, "+w.join(": ..., ")+": ...}":"{key: someKey}";if(!We[x+oe]){var xr=w.length>0?"{"+w.join(": ..., ")+": ...}":"{}";R(`A props object containing a "key" prop is being spread into JSX:
|
|
10
10
|
let props = %s;
|
|
11
11
|
<%s {...props} />
|
|
12
12
|
React keys must be passed directly to JSX without using spread:
|
|
13
13
|
let props = %s;
|
|
14
|
-
<%s key={someKey} {...props} />`,oe,x,xr,x),We[x+oe]=!0}}return e===
|
|
14
|
+
<%s key={someKey} {...props} />`,oe,x,xr,x),We[x+oe]=!0}}return e===u?Pr(p):Tr(p),p}}function Or(e,r,t){return Ye(e,r,t,!0)}function Cr(e,r,t){return Ye(e,r,t,!1)}var kr=Cr,jr=Or;Y.Fragment=u,Y.jsx=kr,Y.jsxs=jr})()),Y}var fe;function Be(){return fe||(fe=1,process.env.NODE_ENV==="production"?N.exports=Ne():N.exports=Je()),N.exports}var A=Be();const Ge=({children:n,authConfig:a})=>{const[c,u]=y.useState(null),[d,m]=y.useState(!0),g=y.useMemo(()=>new ce(a),[a]),b=y.useCallback(async()=>{m(!0);const E=localStorage.getItem(g.config.baseKey+"_access");if(!E){u(null),m(!1);return}try{const T=await X(g,`${g.config.authServer}/me`,{headers:{Authorization:`Bearer ${E}`}});if(!T.ok)throw new Error("not found");const P=await T.json();u({role:P.role.role_name,userId:P.user_id,userName:P.user_name,privileges:P.role.privileges.map(I=>I.privilege.trim())})}catch{u(null)}m(!1)},[]);y.useEffect(()=>{b()},[b]);const _=y.useCallback(()=>{K(g)},[K,g]),C=y.useCallback(()=>{Z(g),u(null)},[Z,g]);return A.jsx(M.Provider,{value:{loadMe:b,loading:d,user:c,login:_,authManager:g,logout:C},children:n})},ze=()=>{const{authManager:n,loadMe:a}=y.useContext(M);return y.useEffect(()=>{n&&($(n),a())},[$,n,a]),A.jsx("div",{})},J=()=>{const n=y.useContext(M);if(!n||!n.authManager)throw new Error("AuthContext not found");return n},de=n=>{const{user:a}=J();return!!a?.privileges?.includes(n)};function He({privilege:n,invalidPage:a,loadingPage:c}){const{loading:u}=J(),d=de(n);return u?c:d?A.jsx(ie.Outlet,{}):a}function Xe({loadingPage:n}){const{authManager:a,login:c,user:u}=J(),[d,m]=y.useState(!0);return y.useEffect(()=>{if(!a)return;a.getToken()?m(!1):c()},[a,u]),a?d?n??A.jsx("div",{children:"Loading..."}):A.jsx(ie.Outlet,{}):A.jsx("p",{children:"invalud config"})}v.AuthContext=M,v.AuthManager=ce,v.AuthProvider=Ge,v.CallbackPage=ze,v.Config=Le,v.PrivilegeGate=He,v.ProtectGate=Xe,v.apiFetch=X,v.handleCallback=$,v.login=K,v.logout=Z,v.refreshToken=se,v.useAuth=J,v.usePrivilege=de,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AuthManager } from './authManager';
|
|
2
|
-
export declare function apiFetch(authManager: AuthManager, url: string, options?: RequestInit): Promise<Response>;
|
|
2
|
+
export declare function apiFetch(authManager: AuthManager, url: string, options?: RequestInit, errorRefresh?: () => void): Promise<Response>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alex-evo-sh-auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/alex-evo-sh-auth.umd.js",
|
|
6
6
|
"module": "./dist/alex-evo-sh-auth.es.js",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"react-router-dom": ">=5.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"react": "^
|
|
36
|
-
"react-dom": "^
|
|
37
|
-
"react-router-dom": "^
|
|
35
|
+
"react": "^19.1.1",
|
|
36
|
+
"react-dom": "^19.1.1",
|
|
37
|
+
"react-router-dom": "^7.8.2",
|
|
38
38
|
"@types/react": "^18.0.28",
|
|
39
39
|
"@types/react-dom": "^18.0.11",
|
|
40
40
|
"@types/react-router-dom": "^5.3.3",
|