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, useMemo as me, useCallback as j, useEffect as C, useContext as B } from "react";
2
- import { Outlet as H } from "react-router-dom";
3
- async function he(r) {
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 ge {
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 = he(this.config).then((o) => (this.setToken(o), o)).finally(() => {
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 we {
38
+ class Re {
39
39
  authServer;
40
40
  clientId;
41
41
  redirectUri;
42
42
  homePage;
43
43
  baseKey;
44
- constructor(t, o, s, a, c) {
45
- this.authServer = t, this.clientId = o, this.redirectUri = s, this.homePage = a, this.baseKey = c;
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 X(r, t, o = {}, s) {
49
- let a = r.getToken();
50
- const c = (d) => fetch(t, {
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 l = await c(a);
58
- return l.status !== 401 ? l : (r.setToken(null), a = await r.getValidToken(), a ? c(a) : (s?.(), l));
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"), s = sessionStorage.getItem("oauth_state"), a = t.get("state");
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 (!a || a !== s)
63
+ if (!s || s !== a)
64
64
  throw new Error("Invalid OAuth state");
65
- const c = sessionStorage.getItem("pkce_verifier"), d = await (await fetch(`${r.config.authServer}/token`, {
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: c
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 _e(r = 64) {
78
+ function he(r = 64) {
79
79
  const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
80
80
  let o = "";
81
- const s = new Uint8Array(r);
82
- crypto.getRandomValues(s);
83
- for (let a = 0; a < s.length; a++)
84
- o += t[s[a] % t.length];
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 pe(r) {
88
- const o = new TextEncoder().encode(r), s = await crypto.subtle.digest("SHA-256", o);
89
- return new Uint8Array(s);
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 ve(r) {
91
+ function _e(r) {
92
92
  return btoa(String.fromCharCode(...Array.from(r))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
93
93
  }
94
- async function N(r) {
95
- const t = _e(64), o = ve(await pe(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 s = crypto.randomUUID();
98
- sessionStorage.setItem("oauth_state", s);
99
- const a = new URLSearchParams({
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: s
105
+ state: a
106
106
  });
107
- window.location.href = `${r.config.authServer}/authorize?${a}`;
107
+ window.location.href = `${r.config.authServer}/authorize?${s}`;
108
108
  }
109
- async function M(r) {
109
+ async function q(r) {
110
110
  try {
111
- await X(r, `${r.config.authServer}/logout`, {
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 N(r);
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 T = { exports: {} }, b = {};
136
- var q;
137
- function be() {
138
- if (q) return b;
139
- q = 1;
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(s, a, c) {
142
- var l = null;
143
- if (c !== void 0 && (l = "" + c), a.key !== void 0 && (l = "" + a.key), "key" in a) {
144
- c = {};
145
- for (var d in a)
146
- d !== "key" && (c[d] = a[d]);
147
- } else c = a;
148
- return a = c.ref, {
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: s,
151
- key: l,
152
- ref: a !== void 0 ? a : null,
153
- props: c
150
+ type: a,
151
+ key: f,
152
+ ref: s !== void 0 ? s : null,
153
+ props: i
154
154
  };
155
155
  }
156
- return b.Fragment = t, b.jsx = o, b.jsxs = o, b;
156
+ return p.Fragment = t, p.jsx = o, p.jsxs = o, p;
157
157
  }
158
- var E = {};
159
- var G;
160
- function Ee() {
161
- return G || (G = 1, process.env.NODE_ENV !== "production" && (function() {
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 === ie ? null : e.displayName || e.name || null;
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 Q:
172
+ case M:
173
173
  return "StrictMode";
174
174
  case oe:
175
175
  return "Suspense";
176
- case ae:
176
+ case se:
177
177
  return "SuspenseList";
178
- case ce:
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 Z:
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 se:
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 i = n.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
218
- return i.call(
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
- u
221
+ l
222
222
  ), t(e);
223
223
  }
224
224
  }
225
- function s(e) {
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 a() {
236
+ function s() {
237
237
  var e = P.A;
238
238
  return e === null ? null : e.getOwner();
239
239
  }
240
- function c() {
240
+ function i() {
241
241
  return Error("react-stack-top-frame");
242
242
  }
243
- function l(e) {
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 i() {
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
- i.isReactWarning = !0, Object.defineProperty(e, "key", {
258
- get: i,
257
+ c.isReactWarning = !0, Object.defineProperty(e, "key", {
258
+ get: c,
259
259
  configurable: !0
260
260
  });
261
261
  }
262
- function S() {
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 R(e, n, i, u, y, O) {
269
- var f = i.ref;
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: i,
275
- _owner: u
276
- }, (f !== void 0 ? f : null) !== null ? Object.defineProperty(e, "ref", {
274
+ props: c,
275
+ _owner: l
276
+ }, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
277
277
  enumerable: !1,
278
- get: S
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: y
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 p(e, n, i, u, y, O) {
302
- var f = n.children;
303
- if (f !== void 0)
304
- if (u)
305
- if (le(f)) {
306
- for (u = 0; u < f.length; u++)
307
- v(f[u]);
308
- Object.freeze && Object.freeze(f);
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 v(f);
313
+ else m(u);
314
314
  if (F.call(n, "key")) {
315
- f = r(e);
316
- var g = Object.keys(n).filter(function(ue) {
315
+ u = r(e);
316
+ var h = Object.keys(n).filter(function(ue) {
317
317
  return ue !== "key";
318
318
  });
319
- u = 0 < g.length ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}", W[f + u] || (g = 0 < g.length ? "{" + g.join(": ..., ") + ": ...}" : "{}", console.error(
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
- f,
328
- g,
329
- f
330
- ), W[f + u] = !0);
328
+ h,
329
+ u
330
+ ), W[u + l] = !0);
331
331
  }
332
- if (f = null, i !== void 0 && (o(i), f = "" + i), l(n) && (o(n.key), f = "" + n.key), "key" in n) {
333
- i = {};
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" && (i[x] = n[x]);
336
- } else i = n;
337
- return f && d(
338
- i,
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
- ), R(
340
+ ), b(
341
341
  e,
342
- f,
343
- i,
344
- a(),
345
- y,
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 h = fe, Y = /* @__PURE__ */ Symbol.for("react.transitional.element"), Z = /* @__PURE__ */ Symbol.for("react.portal"), w = /* @__PURE__ */ Symbol.for("react.fragment"), Q = /* @__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"), ae = /* @__PURE__ */ Symbol.for("react.suspense_list"), se = /* @__PURE__ */ Symbol.for("react.memo"), k = /* @__PURE__ */ Symbol.for("react.lazy"), ce = /* @__PURE__ */ Symbol.for("react.activity"), ie = /* @__PURE__ */ Symbol.for("react.client.reference"), P = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, le = Array.isArray, A = console.createTask ? console.createTask : function() {
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
- h = {
358
+ y = {
359
359
  react_stack_bottom_frame: function(e) {
360
360
  return e();
361
361
  }
362
362
  };
363
- var L, D = {}, J = h.react_stack_bottom_frame.bind(
364
- h,
365
- c
366
- )(), V = A(s(c)), W = {};
367
- E.Fragment = w, E.jsx = function(e, n, i) {
368
- var u = 1e4 > P.recentlyCreatedOwnerStacks++;
369
- return p(
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
- i,
372
+ c,
373
373
  !1,
374
- u ? Error("react-stack-top-frame") : J,
375
- u ? A(s(e)) : V
374
+ l ? Error("react-stack-top-frame") : J,
375
+ l ? A(a(e)) : V
376
376
  );
377
- }, E.jsxs = function(e, n, i) {
378
- var u = 1e4 > P.recentlyCreatedOwnerStacks++;
379
- return p(
377
+ }, v.jsxs = function(e, n, c) {
378
+ var l = 1e4 > P.recentlyCreatedOwnerStacks++;
379
+ return _(
380
380
  e,
381
381
  n,
382
- i,
382
+ c,
383
383
  !0,
384
- u ? Error("react-stack-top-frame") : J,
385
- u ? A(s(e)) : V
384
+ l ? Error("react-stack-top-frame") : J,
385
+ l ? A(a(e)) : V
386
386
  );
387
387
  };
388
- })()), E;
388
+ })()), v;
389
389
  }
390
- var K;
391
- function ye() {
392
- return K || (K = 1, process.env.NODE_ENV === "production" ? T.exports = be() : T.exports = Ee()), T.exports;
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 _ = ye();
395
- const ke = ({ children: r, authConfig: t }) => {
396
- const [o, s] = I(null), [a, c] = I(!0), l = me(() => new ge(t), [t]), d = j(async () => {
397
- c(!0);
398
- const p = localStorage.getItem(l.config.baseKey + "_access");
399
- if (!p) {
400
- s(null), c(!1);
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 v = await X(l, `${l.config.authServer}/me`, {
404
+ const _ = await Z(t, `${t.config.authServer}/me`, {
405
405
  headers: {
406
- Authorization: `Bearer ${p}`
406
+ Authorization: `Bearer ${b}`
407
407
  }
408
408
  });
409
- if (!v.ok) throw new Error("not found");
410
- const m = await v.json();
411
- s({
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((h) => h.privilege.trim())
415
+ privileges: m.role.privileges.map((E) => E.privilege.trim())
416
416
  });
417
417
  } catch {
418
- s(null);
418
+ a(null);
419
419
  }
420
- c(!1);
420
+ i(!1);
421
421
  }, []);
422
- C(() => {
423
- d();
424
- }, [d]);
425
- const S = j(() => {
426
- N(l);
427
- }, [N, l]), R = j(() => {
428
- M(l), s(null);
429
- }, [M, l]);
430
- return /* @__PURE__ */ _.jsx($.Provider, { value: { loadMe: d, loading: a, user: o, login: S, authManager: l, logout: R }, children: r });
431
- }, Pe = () => {
432
- const { authManager: r, loadMe: t } = B($);
433
- return C(() => {
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__ */ _.jsx("div", {});
435
+ }, [z, r, t]), /* @__PURE__ */ g.jsx("div", {});
436
436
  }, U = () => {
437
- const r = B($);
437
+ const r = H($);
438
438
  if (!r || !r.authManager) throw new Error("AuthContext not found");
439
439
  return r;
440
- }, Te = (r) => {
440
+ }, Ee = (r) => {
441
441
  const { user: t } = U();
442
442
  return !!t?.privileges?.includes(r);
443
443
  };
444
- function Ae({ privilege: r, invalidPage: t, loadingPage: o }) {
445
- const { loading: s } = U(), a = Te(r);
446
- return s ? o : a ? /* @__PURE__ */ _.jsx(H, {}) : t;
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 Oe({ loadingPage: r }) {
449
- const { authManager: t, login: o, user: s } = U(), [a, c] = I(!0);
450
- return C(() => {
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() ? c(!1) : o();
453
- }, [t, s]), t ? a ? r ?? /* @__PURE__ */ _.jsx("div", { children: "Loading..." }) : /* @__PURE__ */ _.jsx(H, {}) : /* @__PURE__ */ _.jsx("p", { children: "invalud config" });
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
- ge as AuthManager,
458
- ke as AuthProvider,
459
- Pe as CallbackPage,
460
- we as Config,
461
- Ae as PrivilegeGate,
462
- Oe as ProtectGate,
463
- X as apiFetch,
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
- N as login,
466
- M as logout,
467
- he as refreshToken,
465
+ C as login,
466
+ q as logout,
467
+ me as refreshToken,
468
468
  U as useAuth,
469
- Te as usePrivilege
469
+ Ee as usePrivilege
470
470
  };
@@ -1,6 +1,6 @@
1
- (function(l,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("react-router-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-router-dom"],m):(l=typeof globalThis<"u"?globalThis:l||self,m(l["alex-evo-sh-auth"]={},l.React,l.ReactRouterDOM))})(this,(function(l,m,D){"use strict";async function M(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 J{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=M(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 A(t,r,o={},s){let a=t.getToken();const c=h=>fetch(r,{...o,headers:{...o.headers,Authorization:h?`Bearer ${h}`:""}});let u=await c(a);return u.status!==401?u:(t.setToken(null),a=await t.getValidToken(),a?c(a):(s?.(),u))}async function O(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 S(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 j(t){try{await A(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 S(t)}catch(r){console.error(r)}}const k=m.createContext({login:()=>{},logout:()=>{},loadMe:()=>{},authManager:null,user:null,loading:!1});var R={exports:{}},p={};var V;function ne(){if(V)return p;V=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function o(s,a,c){var u=null;if(c!==void 0&&(u=""+c),a.key!==void 0&&(u=""+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:u,ref:a!==void 0?a:null,props:c}}return p.Fragment=r,p.jsx=o,p.jsxs=o,p}var E={};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,f=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.",f),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 u(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 C(){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 x(e,n,i,f,P,Y){var d=i.ref;return e={$$typeof:K,type:e,key:n,props:i,_owner:f},(d!==void 0?d:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:C}):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:P}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function y(e,n,i,f,P,Y){var d=n.children;if(d!==void 0)if(f)if(ye(d)){for(f=0;f<d.length;f++)T(d[f]);Object.freeze&&Object.freeze(d)}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 T(d);if(B.call(n,"key")){d=t(e);var b=Object.keys(n).filter(function(Te){return Te!=="key"});f=0<b.length?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}",$[d+f]||(b=0<b.length?"{"+b.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
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,d,b,d),$[d+f]=!0)}if(d=null,i!==void 0&&(o(i),d=""+i),u(n)&&(o(n.key),d=""+n.key),"key"in n){i={};for(var L in n)L!=="key"&&(i[L]=n[L])}else i=n;return d&&h(i,typeof e=="function"?e.displayName||e.name||"Unknown":e),x(e,d,i,a(),P,Y)}function T(e){g(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===N&&(e._payload.status==="fulfilled"?g(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function g(e){return typeof e=="object"&&e!==null&&e.$$typeof===K}var v=m,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=v.__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};v={react_stack_bottom_frame:function(e){return e()}};var H,X={},Z=v.react_stack_bottom_frame.bind(v,c)(),Q=U(s(c)),$={};E.Fragment=I,E.jsx=function(e,n,i){var f=1e4>F.recentlyCreatedOwnerStacks++;return y(e,n,i,!1,f?Error("react-stack-top-frame"):Z,f?U(s(e)):Q)},E.jsxs=function(e,n,i){var f=1e4>F.recentlyCreatedOwnerStacks++;return y(e,n,i,!0,f?Error("react-stack-top-frame"):Z,f?U(s(e)):Q)}})()),E}var z;function ae(){return z||(z=1,process.env.NODE_ENV==="production"?R.exports=ne():R.exports=oe()),R.exports}var _=ae();const se=({children:t,authConfig:r})=>{const[o,s]=m.useState(null),[a,c]=m.useState(!0),u=m.useMemo(()=>new J(r),[r]),h=m.useCallback(async()=>{c(!0);const y=localStorage.getItem(u.config.baseKey+"_access");if(!y){s(null),c(!1);return}try{const T=await A(u,`${u.config.authServer}/me`,{headers:{Authorization:`Bearer ${y}`}});if(!T.ok)throw new Error("not found");const g=await T.json();s({role:g.role.role_name,userId:g.user_id,userName:g.user_name,privileges:g.role.privileges.map(v=>v.privilege.trim())})}catch{s(null)}c(!1)},[]);m.useEffect(()=>{h()},[h]);const C=m.useCallback(()=>{S(u)},[S,u]),x=m.useCallback(()=>{j(u),s(null)},[j,u]);return _.jsx(k.Provider,{value:{loadMe:h,loading:a,user:o,login:C,authManager:u,logout:x},children:t})},ce=()=>{const{authManager:t,loadMe:r}=m.useContext(k);return m.useEffect(()=>{t&&(O(t),r())},[O,t,r]),_.jsx("div",{})},w=()=>{const t=m.useContext(k);if(!t||!t.authManager)throw new Error("AuthContext not found");return t},G=t=>{const{user:r}=w();return!!r?.privileges?.includes(t)};function ie({privilege:t,invalidPage:r,loadingPage:o}){const{loading:s}=w(),a=G(t);return s?o:a?_.jsx(D.Outlet,{}):r}function le({loadingPage:t}){const{authManager:r,login:o,user:s}=w(),[a,c]=m.useState(!0);return m.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=k,l.AuthManager=J,l.AuthProvider=se,l.CallbackPage=ce,l.Config=q,l.PrivilegeGate=ie,l.ProtectGate=le,l.apiFetch=A,l.handleCallback=O,l.login=S,l.logout=j,l.refreshToken=M,l.useAuth=w,l.usePrivilege=G,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}));
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 { Config } from '../helpers/config';
1
+ import { AuthManager } from '../helpers/authManager';
2
2
  type IAuthProvider = {
3
- authConfig: Config;
3
+ authManager: AuthManager;
4
4
  children: React.ReactNode;
5
5
  };
6
- export declare const AuthProvider: ({ children, authConfig }: IAuthProvider) => import("react/jsx-runtime").JSX.Element;
6
+ export declare const AuthProvider: ({ children, authManager }: IAuthProvider) => import("react/jsx-runtime").JSX.Element;
7
7
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alex-evo-sh-auth",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "main": "./dist/alex-evo-sh-auth.umd.js",
6
6
  "module": "./dist/alex-evo-sh-auth.es.js",