@versini/auth-provider 4.4.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -13,7 +13,10 @@ type AuthState = {
13
13
  isLoading: boolean;
14
14
  isAuthenticated: boolean;
15
15
  logoutReason?: string;
16
- userId?: string;
16
+ user?: {
17
+ userId?: string;
18
+ username?: string;
19
+ };
17
20
  };
18
21
 
19
22
  type LoginType = (
package/dist/index.js CHANGED
@@ -1,27 +1,27 @@
1
1
  import { jsx as We } from "react/jsx-runtime";
2
- import * as D from "react";
2
+ import * as U from "react";
3
3
  import { createContext as Je, useState as xe, useCallback as je, useEffect as Me, useContext as Ve } from "react";
4
4
  /*!
5
- @versini/auth-provider v4.4.0
5
+ @versini/auth-provider v5.0.1
6
6
  © 2024 gizmette.com
7
7
  */
8
8
  try {
9
9
  window.__VERSINI_AUTH_CLIENT__ || (window.__VERSINI_AUTH_CLIENT__ = {
10
- version: "4.4.0",
11
- buildTime: "06/29/2024 12:23 PM EDT",
10
+ version: "5.0.1",
11
+ buildTime: "07/03/2024 06:46 PM EDT",
12
12
  homepage: "https://github.com/aversini/auth-client",
13
13
  license: "MIT"
14
14
  });
15
15
  } catch {
16
16
  }
17
17
  /*!
18
- @versini/auth-common v2.10.0
18
+ @versini/auth-common v2.10.1
19
19
  © 2024 gizmette.com
20
20
  */
21
21
  try {
22
22
  window.__VERSINI_AUTH_COMMON__ || (window.__VERSINI_AUTH_COMMON__ = {
23
- version: "2.10.0",
24
- buildTime: "06/29/2024 12:23 PM EDT",
23
+ version: "2.10.1",
24
+ buildTime: "07/03/2024 06:46 PM EDT",
25
25
  homepage: "https://github.com/aversini/auth-client",
26
26
  license: "MIT"
27
27
  });
@@ -35,11 +35,12 @@ const B = {
35
35
  REFRESH_TOKEN: "refresh_token"
36
36
  }, Ye = {
37
37
  CLIENT_ID: "X-Auth-ClientId"
38
- }, y = {
38
+ }, f = {
39
39
  ALG: "RS256",
40
40
  USER_ID_KEY: "sub",
41
41
  TOKEN_ID_KEY: "__raw",
42
42
  NONCE_KEY: "_nonce",
43
+ USERNAME_KEY: "username",
43
44
  ISSUER: "gizmette.com"
44
45
  }, Be = `-----BEGIN PUBLIC KEY-----
45
46
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsF6i3Jd9fY/3COqCw/m7
@@ -53,7 +54,7 @@ awIDAQAB
53
54
  AUTHENTICATE: "authenticate",
54
55
  CODE: "code",
55
56
  LOGOUT: "logout"
56
- }, G = crypto, Ae = (e) => e instanceof CryptoKey, K = new TextEncoder(), q = new TextDecoder();
57
+ }, G = crypto, Ae = (e) => e instanceof CryptoKey, N = new TextEncoder(), q = new TextDecoder();
57
58
  function Fe(...e) {
58
59
  const t = e.reduce((n, { length: s }) => n + s, 0), r = new Uint8Array(t);
59
60
  let a = 0;
@@ -84,7 +85,7 @@ class C extends Error {
84
85
  super(t), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) == null || r.call(Error, this, this.constructor);
85
86
  }
86
87
  }
87
- class g extends C {
88
+ class A extends C {
88
89
  static get code() {
89
90
  return "ERR_JWT_CLAIM_VALIDATION_FAILED";
90
91
  }
@@ -108,7 +109,7 @@ class qe extends C {
108
109
  return "ERR_JOSE_ALG_NOT_ALLOWED";
109
110
  }
110
111
  }
111
- let T = class extends C {
112
+ let k = class extends C {
112
113
  constructor() {
113
114
  super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
114
115
  }
@@ -300,7 +301,7 @@ function at(e) {
300
301
  }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
301
302
  break;
302
303
  default:
303
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
304
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
304
305
  }
305
306
  break;
306
307
  }
@@ -322,7 +323,7 @@ function at(e) {
322
323
  t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
323
324
  break;
324
325
  default:
325
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
326
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
326
327
  }
327
328
  break;
328
329
  }
@@ -338,12 +339,12 @@ function at(e) {
338
339
  t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
339
340
  break;
340
341
  default:
341
- throw new T('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
342
+ throw new k('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
342
343
  }
343
344
  break;
344
345
  }
345
346
  default:
346
- throw new T('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
347
+ throw new k('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
347
348
  }
348
349
  return { algorithm: t, keyUsages: r };
349
350
  }
@@ -358,49 +359,49 @@ const nt = async (e) => {
358
359
  return delete n.alg, delete n.use, G.subtle.importKey("jwk", n, ...a);
359
360
  }, ke = (e) => M(e);
360
361
  let Q, Z;
361
- const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", Re = async (e, t, r, a) => {
362
+ const Re = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject", Ie = async (e, t, r, a) => {
362
363
  let n = e.get(t);
363
364
  if (n != null && n[a])
364
365
  return n[a];
365
366
  const s = await nt({ ...r, alg: a });
366
367
  return n ? n[a] = s : e.set(t, { [a]: s }), s;
367
368
  }, ot = (e, t) => {
368
- if (Ie(e)) {
369
+ if (Re(e)) {
369
370
  let r = e.export({ format: "jwk" });
370
- return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? ke(r.k) : (Z || (Z = /* @__PURE__ */ new WeakMap()), Re(Z, e, r, t));
371
+ return delete r.d, delete r.dp, delete r.dq, delete r.p, delete r.q, delete r.qi, r.k ? ke(r.k) : (Z || (Z = /* @__PURE__ */ new WeakMap()), Ie(Z, e, r, t));
371
372
  }
372
373
  return e;
373
374
  }, st = (e, t) => {
374
- if (Ie(e)) {
375
+ if (Re(e)) {
375
376
  let r = e.export({ format: "jwk" });
376
- return r.k ? ke(r.k) : (Q || (Q = /* @__PURE__ */ new WeakMap()), Re(Q, e, r, t));
377
+ return r.k ? ke(r.k) : (Q || (Q = /* @__PURE__ */ new WeakMap()), Ie(Q, e, r, t));
377
378
  }
378
379
  return e;
379
- }, ct = { normalizePublicKey: ot, normalizePrivateKey: st }, v = (e, t, r = 0) => {
380
+ }, ct = { normalizePublicKey: ot, normalizePrivateKey: st }, T = (e, t, r = 0) => {
380
381
  r === 0 && (t.unshift(t.length), t.unshift(6));
381
382
  const a = e.indexOf(t[0], r);
382
383
  if (a === -1)
383
384
  return !1;
384
385
  const n = e.subarray(a, a + t.length);
385
- return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || v(e, t, a + 1);
386
+ return n.length !== t.length ? !1 : n.every((s, o) => s === t[o]) || T(e, t, a + 1);
386
387
  }, ue = (e) => {
387
388
  switch (!0) {
388
- case v(e, [42, 134, 72, 206, 61, 3, 1, 7]):
389
+ case T(e, [42, 134, 72, 206, 61, 3, 1, 7]):
389
390
  return "P-256";
390
- case v(e, [43, 129, 4, 0, 34]):
391
+ case T(e, [43, 129, 4, 0, 34]):
391
392
  return "P-384";
392
- case v(e, [43, 129, 4, 0, 35]):
393
+ case T(e, [43, 129, 4, 0, 35]):
393
394
  return "P-521";
394
- case v(e, [43, 101, 110]):
395
+ case T(e, [43, 101, 110]):
395
396
  return "X25519";
396
- case v(e, [43, 101, 111]):
397
+ case T(e, [43, 101, 111]):
397
398
  return "X448";
398
- case v(e, [43, 101, 112]):
399
+ case T(e, [43, 101, 112]):
399
400
  return "Ed25519";
400
- case v(e, [43, 101, 113]):
401
+ case T(e, [43, 101, 113]):
401
402
  return "Ed448";
402
403
  default:
403
- throw new T("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
404
+ throw new k("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
404
405
  }
405
406
  }, it = async (e, t, r, a, n) => {
406
407
  let s, o;
@@ -446,7 +447,7 @@ const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
446
447
  s = { name: ue(i) }, o = ["verify"];
447
448
  break;
448
449
  default:
449
- throw new T('Invalid or unsupported "alg" (Algorithm) value');
450
+ throw new k('Invalid or unsupported "alg" (Algorithm) value');
450
451
  }
451
452
  return G.subtle.importKey(t, i, s, !1, o);
452
453
  }, ut = (e, t, r) => it(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
@@ -485,7 +486,7 @@ function yt(e, t, r, a, n) {
485
486
  r !== void 0 ? s = new Map([...Object.entries(r), ...t.entries()]) : s = t;
486
487
  for (const o of a.crit) {
487
488
  if (!s.has(o))
488
- throw new T(`Extension Header Parameter "${o}" is not recognized`);
489
+ throw new k(`Extension Header Parameter "${o}" is not recognized`);
489
490
  if (n[o] === void 0)
490
491
  throw new e(`Extension Header Parameter "${o}" is missing`);
491
492
  if (s.get(o) && a[o] === void 0)
@@ -521,7 +522,7 @@ function mt(e, t) {
521
522
  case "EdDSA":
522
523
  return { name: t.name };
523
524
  default:
524
- throw new T(`alg ${e} is not supported either by JOSE or your javascript runtime`);
525
+ throw new k(`alg ${e} is not supported either by JOSE or your javascript runtime`);
525
526
  }
526
527
  }
527
528
  async function wt(e, t, r) {
@@ -534,7 +535,7 @@ async function wt(e, t, r) {
534
535
  }
535
536
  throw new TypeError(ie(t, ...Y, "Uint8Array"));
536
537
  }
537
- const St = async (e, t, r, a) => {
538
+ const Et = async (e, t, r, a) => {
538
539
  const n = await wt(e, t, "verify");
539
540
  rt(e, n);
540
541
  const s = mt(e, n.algorithm);
@@ -544,7 +545,7 @@ const St = async (e, t, r, a) => {
544
545
  return !1;
545
546
  }
546
547
  };
547
- async function Et(e, t, r) {
548
+ async function St(e, t, r) {
548
549
  if (!ne(e))
549
550
  throw new h("Flattened JWS must be an object");
550
551
  if (e.protected === void 0 && e.header === void 0)
@@ -560,8 +561,8 @@ async function Et(e, t, r) {
560
561
  let a = {};
561
562
  if (e.protected)
562
563
  try {
563
- const m = M(e.protected);
564
- a = JSON.parse(q.decode(m));
564
+ const E = M(e.protected);
565
+ a = JSON.parse(q.decode(E));
565
566
  } catch {
566
567
  throw new h("JWS Protected Header is invalid");
567
568
  }
@@ -587,14 +588,14 @@ async function Et(e, t, r) {
587
588
  throw new h("JWS Payload must be a string or an Uint8Array instance");
588
589
  let u = !1;
589
590
  typeof t == "function" && (t = await t(a, e), u = !0), pt(i, t, "verify");
590
- const f = Fe(K.encode(e.protected ?? ""), K.encode("."), typeof e.payload == "string" ? K.encode(e.payload) : e.payload);
591
- let p;
591
+ const w = Fe(N.encode(e.protected ?? ""), N.encode("."), typeof e.payload == "string" ? N.encode(e.payload) : e.payload);
592
+ let y;
592
593
  try {
593
- p = M(e.signature);
594
+ y = M(e.signature);
594
595
  } catch {
595
596
  throw new h("Failed to base64url decode the signature");
596
597
  }
597
- if (!await St(i, t, p, f))
598
+ if (!await Et(i, t, y, w))
598
599
  throw new ze();
599
600
  let _;
600
601
  if (o)
@@ -604,7 +605,7 @@ async function Et(e, t, r) {
604
605
  throw new h("Failed to base64url decode the payload");
605
606
  }
606
607
  else
607
- typeof e.payload == "string" ? _ = K.encode(e.payload) : _ = e.payload;
608
+ typeof e.payload == "string" ? _ = N.encode(e.payload) : _ = e.payload;
608
609
  const S = { payload: _ };
609
610
  return e.protected !== void 0 && (S.protectedHeader = a), e.header !== void 0 && (S.unprotectedHeader = e.header), u ? { ...S, key: t } : S;
610
611
  }
@@ -614,7 +615,7 @@ async function gt(e, t, r) {
614
615
  const { 0: a, 1: n, 2: s, length: o } = e.split(".");
615
616
  if (o !== 3)
616
617
  throw new h("Invalid Compact JWS");
617
- const i = await Et({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
618
+ const i = await St({ payload: n, protected: a, signature: s }, t, r), c = { payload: i.payload, protectedHeader: i.protectedHeader };
618
619
  return typeof t == "function" ? { ...c, key: i.key } : c;
619
620
  }
620
621
  const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe * 24, bt = oe * 7, _t = oe * 365.25, vt = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i, de = (e) => {
@@ -670,57 +671,57 @@ const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe
670
671
  throw new be("JWT Claims Set must be a top-level JSON object");
671
672
  const { typ: n } = r;
672
673
  if (n && (typeof e.typ != "string" || le(e.typ) !== le(n)))
673
- throw new g('unexpected "typ" JWT header value', a, "typ", "check_failed");
674
- const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: u } = r, f = [...s];
675
- u !== void 0 && f.push("iat"), c !== void 0 && f.push("aud"), i !== void 0 && f.push("sub"), o !== void 0 && f.push("iss");
676
- for (const m of new Set(f.reverse()))
677
- if (!(m in a))
678
- throw new g(`missing required "${m}" claim`, a, m, "missing");
674
+ throw new A('unexpected "typ" JWT header value', a, "typ", "check_failed");
675
+ const { requiredClaims: s = [], issuer: o, subject: i, audience: c, maxTokenAge: u } = r, w = [...s];
676
+ u !== void 0 && w.push("iat"), c !== void 0 && w.push("aud"), i !== void 0 && w.push("sub"), o !== void 0 && w.push("iss");
677
+ for (const E of new Set(w.reverse()))
678
+ if (!(E in a))
679
+ throw new A(`missing required "${E}" claim`, a, E, "missing");
679
680
  if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
680
- throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
681
+ throw new A('unexpected "iss" claim value', a, "iss", "check_failed");
681
682
  if (i && a.sub !== i)
682
- throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
683
+ throw new A('unexpected "sub" claim value', a, "sub", "check_failed");
683
684
  if (c && !Tt(a.aud, typeof c == "string" ? [c] : c))
684
- throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
685
- let p;
685
+ throw new A('unexpected "aud" claim value', a, "aud", "check_failed");
686
+ let y;
686
687
  switch (typeof r.clockTolerance) {
687
688
  case "string":
688
- p = de(r.clockTolerance);
689
+ y = de(r.clockTolerance);
689
690
  break;
690
691
  case "number":
691
- p = r.clockTolerance;
692
+ y = r.clockTolerance;
692
693
  break;
693
694
  case "undefined":
694
- p = 0;
695
+ y = 0;
695
696
  break;
696
697
  default:
697
698
  throw new TypeError("Invalid clockTolerance option type");
698
699
  }
699
700
  const { currentDate: _ } = r, S = At(_ || /* @__PURE__ */ new Date());
700
701
  if ((a.iat !== void 0 || u) && typeof a.iat != "number")
701
- throw new g('"iat" claim must be a number', a, "iat", "invalid");
702
+ throw new A('"iat" claim must be a number', a, "iat", "invalid");
702
703
  if (a.nbf !== void 0) {
703
704
  if (typeof a.nbf != "number")
704
- throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
705
- if (a.nbf > S + p)
706
- throw new g('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
705
+ throw new A('"nbf" claim must be a number', a, "nbf", "invalid");
706
+ if (a.nbf > S + y)
707
+ throw new A('"nbf" claim timestamp check failed', a, "nbf", "check_failed");
707
708
  }
708
709
  if (a.exp !== void 0) {
709
710
  if (typeof a.exp != "number")
710
- throw new g('"exp" claim must be a number', a, "exp", "invalid");
711
- if (a.exp <= S - p)
711
+ throw new A('"exp" claim must be a number', a, "exp", "invalid");
712
+ if (a.exp <= S - y)
712
713
  throw new ce('"exp" claim timestamp check failed', a, "exp", "check_failed");
713
714
  }
714
715
  if (u) {
715
- const m = S - a.iat, k = typeof u == "number" ? u : de(u);
716
- if (m - p > k)
716
+ const E = S - a.iat, R = typeof u == "number" ? u : de(u);
717
+ if (E - y > R)
717
718
  throw new ce('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
718
- if (m < 0 - p)
719
- throw new g('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
719
+ if (E < 0 - y)
720
+ throw new A('"iat" claim timestamp check failed (it should be in the past)', a, "iat", "check_failed");
720
721
  }
721
722
  return a;
722
723
  };
723
- async function It(e, t, r) {
724
+ async function Rt(e, t, r) {
724
725
  var a;
725
726
  const n = await gt(e, t, r);
726
727
  if ((a = n.protectedHeader.crit) != null && a.includes("b64") && n.protectedHeader.b64 === !1)
@@ -730,9 +731,9 @@ async function It(e, t, r) {
730
731
  }
731
732
  const H = async (e) => {
732
733
  try {
733
- const t = y.ALG, r = await dt(Be, t);
734
- return await It(e, r, {
735
- issuer: y.ISSUER
734
+ const t = f.ALG, r = await dt(Be, t);
735
+ return await Rt(e, r, {
736
+ issuer: f.ISSUER
736
737
  });
737
738
  } catch {
738
739
  return;
@@ -741,7 +742,7 @@ const H = async (e) => {
741
742
  var d = [];
742
743
  for (var ee = 0; ee < 256; ++ee)
743
744
  d.push((ee + 256).toString(16).slice(1));
744
- function Rt(e, t = 0) {
745
+ function It(e, t = 0) {
745
746
  return (d[e[t + 0]] + d[e[t + 1]] + d[e[t + 2]] + d[e[t + 3]] + "-" + d[e[t + 4]] + d[e[t + 5]] + "-" + d[e[t + 6]] + d[e[t + 7]] + "-" + d[e[t + 8]] + d[e[t + 9]] + "-" + d[e[t + 10]] + d[e[t + 11]] + d[e[t + 12]] + d[e[t + 13]] + d[e[t + 14]] + d[e[t + 15]]).toLowerCase();
746
747
  }
747
748
  var L, Ct = new Uint8Array(16);
@@ -759,7 +760,7 @@ function pe(e, t, r) {
759
760
  return he.randomUUID();
760
761
  e = e || {};
761
762
  var a = e.random || (e.rng || Pt)();
762
- return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Rt(a);
763
+ return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, It(a);
763
764
  }
764
765
  const ye = globalThis.crypto, Dt = (e) => `${pe()}${pe()}`.slice(0, e), Ut = (e) => btoa(
765
766
  [...new Uint8Array(e)].map((t) => String.fromCharCode(t)).join("")
@@ -772,7 +773,7 @@ async function Ht(e) {
772
773
  const t = new TextEncoder().encode(e), r = await ye.subtle.digest("SHA-256", t);
773
774
  return Ut(r).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
774
775
  }
775
- async function Nt(e) {
776
+ async function Kt(e) {
776
777
  const r = Dt(43), a = await Ht(r);
777
778
  return {
778
779
  code_verifier: r,
@@ -787,32 +788,32 @@ const fe = (e, t) => {
787
788
  typeof t == "function" ? t() : t
788
789
  );
789
790
  window.localStorage.setItem(e, r), Oe(e, r);
790
- }, Kt = (e) => {
791
+ }, Nt = (e) => {
791
792
  window.localStorage.removeItem(e), Oe(e, null);
792
793
  }, me = (e) => window.localStorage.getItem(e), $t = (e) => (window.addEventListener("storage", e), () => window.removeEventListener("storage", e));
793
794
  function W({
794
795
  key: e,
795
796
  initialValue: t
796
797
  }) {
797
- const r = () => me(e), a = D.useSyncExternalStore(
798
+ const r = () => me(e), a = U.useSyncExternalStore(
798
799
  $t,
799
800
  r
800
- ), n = D.useCallback(
801
+ ), n = U.useCallback(
801
802
  (i) => {
802
803
  try {
803
804
  const c = typeof i == "function" ? i(JSON.parse(a)) : i;
804
- c == null ? Kt(e) : fe(e, c);
805
+ c == null ? Nt(e) : fe(e, c);
805
806
  } catch (c) {
806
807
  console.warn(c);
807
808
  }
808
809
  },
809
810
  [e, a]
810
- ), s = D.useCallback(() => {
811
+ ), s = U.useCallback(() => {
811
812
  n(t);
812
- }, [t, n]), o = D.useCallback(() => {
813
+ }, [t, n]), o = U.useCallback(() => {
813
814
  n(null);
814
815
  }, [n]);
815
- return D.useEffect(() => {
816
+ return U.useEffect(() => {
816
817
  try {
817
818
  me(e) === null && typeof t < "u" && fe(e, t);
818
819
  } catch (i) {
@@ -843,7 +844,7 @@ function jt(e, t, r) {
843
844
  var a = e.random || (e.rng || Jt)();
844
845
  return a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, Lt(a);
845
846
  }
846
- const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.", Se = "Login failed. Please try again.", U = "Error getting access token, please re-authenticate.", Vt = "You forgot to wrap your component in <AuthProvider>.", Ee = {
847
+ const re = "Oops! It looks like your session has expired. For your security, please log in again to continue.", Mt = "Your session has been successfully terminated.", Ee = "Login failed. Please try again.", v = "Error getting access token, please re-authenticate.", Vt = "You forgot to wrap your component in <AuthProvider>.", Se = {
847
848
  dev: "https://auth.gizmette.local.com:3003",
848
849
  prod: "https://mylogin.gizmette.com"
849
850
  }, x = "@@auth@@", Yt = process.env.NODE_ENV === "production", Bt = !Yt, z = async ({
@@ -853,7 +854,7 @@ const re = "Oops! It looks like your session has expired. For your security, ple
853
854
  }) => {
854
855
  try {
855
856
  const a = await fetch(
856
- Bt ? `${Ee.dev}/${e}` : `${Ee.prod}/${e}`,
857
+ Bt ? `${Se.dev}/${e}` : `${Se.prod}/${e}`,
857
858
  {
858
859
  credentials: "include",
859
860
  method: "POST",
@@ -922,11 +923,11 @@ const re = "Oops! It looks like your session has expired. For your security, ple
922
923
  code_verifier: i
923
924
  }
924
925
  }), u = await H(c.data.idToken);
925
- return u && u.payload[y.USER_ID_KEY] !== "" && u.payload[y.NONCE_KEY] === a ? {
926
+ return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === a ? {
926
927
  idToken: c.data.idToken,
927
928
  accessToken: c.data.accessToken,
928
929
  refreshToken: c.data.refreshToken,
929
- userId: u.payload[y.USER_ID_KEY],
930
+ userId: u.payload[f.USER_ID_KEY],
930
931
  status: !0
931
932
  } : {
932
933
  status: !1
@@ -981,10 +982,10 @@ const re = "Oops! It looks like your session has expired. For your security, ple
981
982
  accessToken: n
982
983
  }
983
984
  }), o = await H(s.data.accessToken);
984
- return o && o.payload[y.USER_ID_KEY] !== "" && o.payload[y.NONCE_KEY] === r ? {
985
+ return o && o.payload[f.USER_ID_KEY] !== "" && o.payload[f.NONCE_KEY] === r ? {
985
986
  accessToken: s.data.accessToken,
986
987
  refreshToken: s.data.refreshToken,
987
- userId: o.payload[y.USER_ID_KEY],
988
+ userId: o.payload[f.USER_ID_KEY],
988
989
  status: !0
989
990
  } : {
990
991
  status: !1
@@ -1013,45 +1014,48 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1013
1014
  key: `${x}::${r}::@@user@@`
1014
1015
  }), [o, i, , c] = W({
1015
1016
  key: `${x}::${r}::@@access@@`
1016
- }), [u, f, , p] = W(
1017
+ }), [u, w, , y] = W(
1017
1018
  {
1018
1019
  key: `${x}::${r}::@@refresh@@`
1019
1020
  }
1020
- ), [_, S, , m] = W({
1021
+ ), [_, S, , E] = W({
1021
1022
  key: `${x}::${r}::@@nonce@@`
1022
- }), [k, N] = xe({
1023
+ }), [R, K] = xe({
1023
1024
  isLoading: !0,
1024
1025
  isAuthenticated: !1,
1025
- userId: "",
1026
+ user: void 0,
1026
1027
  logoutReason: ""
1027
- }), A = je(
1028
- (w) => {
1029
- N({
1028
+ }), g = je(
1029
+ (p) => {
1030
+ K({
1030
1031
  isLoading: !1,
1031
1032
  isAuthenticated: !1,
1032
- userId: "",
1033
- logoutReason: w || re
1034
- }), s(), c(), p(), m();
1033
+ user: void 0,
1034
+ logoutReason: p || re
1035
+ }), s(), c(), y(), E();
1035
1036
  },
1036
- [s, c, m, p]
1037
+ [s, c, E, y]
1037
1038
  );
1038
1039
  Me(() => {
1039
- k.isLoading && a !== null && (async () => {
1040
+ R.isLoading && a !== null && (async () => {
1040
1041
  try {
1041
- const w = await H(a);
1042
- w && w.payload[y.USER_ID_KEY] !== "" ? N({
1042
+ const p = await H(a);
1043
+ p && p.payload[f.USER_ID_KEY] !== "" ? K({
1043
1044
  isLoading: !1,
1044
1045
  isAuthenticated: !0,
1045
- userId: w.payload[y.USER_ID_KEY],
1046
+ user: {
1047
+ userId: p.payload[f.USER_ID_KEY],
1048
+ username: p.payload[f.USERNAME_KEY]
1049
+ },
1046
1050
  logoutReason: ""
1047
- }) : (A(re), await ae({
1051
+ }) : (g(re), await ae({
1048
1052
  idToken: a,
1049
1053
  accessToken: o,
1050
1054
  refreshToken: u,
1051
1055
  clientId: r
1052
1056
  }));
1053
1057
  } catch {
1054
- A(re), await ae({
1058
+ g(re), await ae({
1055
1059
  idToken: a,
1056
1060
  accessToken: o,
1057
1061
  refreshToken: u,
@@ -1060,94 +1064,101 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1060
1064
  }
1061
1065
  })();
1062
1066
  }, [
1063
- k.isLoading,
1067
+ R.isLoading,
1064
1068
  o,
1065
1069
  a,
1066
1070
  u,
1067
1071
  r,
1068
- A
1072
+ g
1069
1073
  ]);
1070
- const Ue = async (w, P, I) => {
1071
- const R = jt();
1072
- if (S(R), I === B.CODE) {
1073
- const { code_verifier: $e, code_challenge: Le } = await Nt(), se = await Ft({
1074
- nonce: R,
1074
+ const Ue = async (p, P, I) => {
1075
+ const m = jt();
1076
+ if (S(m), I === B.CODE) {
1077
+ const { code_verifier: $e, code_challenge: Le } = await Kt(), se = await Ft({
1078
+ nonce: m,
1075
1079
  clientId: r,
1076
1080
  code_challenge: Le
1077
1081
  });
1078
1082
  if (se.status) {
1079
- const O = await ge({
1080
- username: w,
1083
+ const D = await ge({
1084
+ username: p,
1081
1085
  password: P,
1082
1086
  clientId: r,
1083
1087
  sessionExpiration: t,
1084
- nonce: R,
1088
+ nonce: m,
1085
1089
  type: I,
1086
1090
  code: se.code,
1087
1091
  code_verifier: $e
1088
1092
  });
1089
- return O.status ? (n(O.idToken), i(O.accessToken), f(O.refreshToken), N({
1093
+ return D.status ? (n(D.idToken), i(D.accessToken), w(D.refreshToken), K({
1090
1094
  isLoading: !1,
1091
1095
  isAuthenticated: !0,
1092
- userId: O.userId,
1096
+ user: {
1097
+ userId: D.userId,
1098
+ username: p
1099
+ },
1093
1100
  logoutReason: ""
1094
- }), !0) : (A(Se), !1);
1101
+ }), !0) : (g(Ee), !1);
1095
1102
  }
1096
1103
  return !1;
1097
1104
  }
1098
- const E = await ge({
1099
- username: w,
1105
+ const O = await ge({
1106
+ username: p,
1100
1107
  password: P,
1101
1108
  clientId: r,
1102
1109
  sessionExpiration: t,
1103
- nonce: R,
1110
+ nonce: m,
1104
1111
  type: I
1105
1112
  });
1106
- return E.status ? (n(E.idToken), i(E.accessToken), f(E.refreshToken), N({
1113
+ return O.status ? (n(O.idToken), i(O.accessToken), w(O.refreshToken), K({
1107
1114
  isLoading: !1,
1108
1115
  isAuthenticated: !0,
1109
- userId: E.userId
1110
- }), !0) : (A(Se), !1);
1116
+ user: {
1117
+ userId: O.userId,
1118
+ username: p
1119
+ }
1120
+ }), !0) : (g(Ee), !1);
1111
1121
  }, He = async () => {
1112
- A(Mt), await ae({
1122
+ g(Mt), await ae({
1113
1123
  idToken: a,
1114
1124
  accessToken: o,
1115
1125
  refreshToken: u,
1116
1126
  clientId: r
1117
1127
  });
1118
- }, Ne = async () => {
1119
- const { isAuthenticated: w, userId: P } = k;
1128
+ }, Ke = async () => {
1129
+ const { isAuthenticated: p, user: P } = R;
1120
1130
  try {
1121
- if (w && P && o) {
1122
- const I = await H(o);
1123
- if (I && I.payload[y.USER_ID_KEY] !== "")
1124
- return o;
1125
- const R = await H(u);
1126
- if (R && R.payload[y.USER_ID_KEY] !== "") {
1127
- const E = await Gt({
1131
+ if (p && P && P.userId) {
1132
+ if (o) {
1133
+ const m = await H(o);
1134
+ if (m && m.payload[f.USER_ID_KEY] !== "")
1135
+ return o;
1136
+ }
1137
+ const I = await H(u);
1138
+ if (I && I.payload[f.USER_ID_KEY] !== "") {
1139
+ const m = await Gt({
1128
1140
  clientId: r,
1129
- userId: P,
1141
+ userId: P.userId,
1130
1142
  nonce: _,
1131
1143
  refreshToken: u,
1132
1144
  accessToken: o
1133
1145
  });
1134
- if (E.status)
1135
- return i(E.accessToken), f(E.refreshToken), E.accessToken;
1136
- A(U);
1146
+ return m.status ? (i(m.accessToken), w(m.refreshToken), m.accessToken) : (g(v), console.error(v), "");
1137
1147
  }
1138
- return A(U), console.error(U), "";
1148
+ return g(v), console.error(v), "";
1139
1149
  }
1150
+ return g(v), console.error(v), "";
1140
1151
  } catch {
1141
- return A(U), console.error(U), "";
1152
+ return g(v), console.error(v), "";
1142
1153
  }
1143
- }, Ke = () => {
1144
- if (k.isAuthenticated && a)
1154
+ }, Ne = () => {
1155
+ if (R.isAuthenticated && a)
1145
1156
  return a;
1146
1157
  };
1147
1158
  return /* @__PURE__ */ We(
1148
1159
  De.Provider,
1149
1160
  {
1150
- value: { ...k, login: Ue, logout: He, getAccessToken: Ne, getIdToken: Ke },
1161
+ value: { ...R, login: Ue, logout: He, getAccessToken: Ke, getIdToken: Ne },
1151
1162
  children: e
1152
1163
  }
1153
1164
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/auth-provider",
3
- "version": "4.4.0",
3
+ "version": "5.0.1",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -44,10 +44,10 @@
44
44
  "react-dom": "18.3.1"
45
45
  },
46
46
  "dependencies": {
47
- "@versini/auth-common": "2.10.0",
47
+ "@versini/auth-common": "2.10.1",
48
48
  "@versini/ui-hooks": "4.0.0",
49
- "jose": "5.6.2",
49
+ "jose": "5.6.3",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "5abd68fc5595a95360b4e80088cc39c067722085"
52
+ "gitHead": "e58285842ff21caaa538c6c0e41b840a2df569cd"
53
53
  }