@versini/auth-provider 4.4.0 → 5.0.0

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
@@ -2,26 +2,26 @@ import { jsx as We } from "react/jsx-runtime";
2
2
  import * as D 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.0
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.0",
11
+ buildTime: "06/29/2024 02:02 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: "06/29/2024 02:02 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;
@@ -92,7 +93,7 @@ class g extends C {
92
93
  super(t), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = a, this.reason = n, this.payload = r;
93
94
  }
94
95
  }
95
- class ce extends C {
96
+ class ie extends C {
96
97
  static get code() {
97
98
  return "ERR_JWT_EXPIRED";
98
99
  }
@@ -232,7 +233,7 @@ function _e(e, t, ...r) {
232
233
  r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
233
234
  return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && (a = t.constructor) != null && a.name && (e += ` Received an instance of ${t.constructor.name}`), e;
234
235
  }
235
- const ie = (e, ...t) => _e("Key must be ", e, ...t);
236
+ const ce = (e, ...t) => _e("Key must be ", e, ...t);
236
237
  function ve(e, t, ...r) {
237
238
  return _e(`Key for the ${e} algorithm must be `, t, ...r);
238
239
  }
@@ -358,25 +359,25 @@ 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
+ }, it = { normalizePublicKey: ot, normalizePrivateKey: st }, v = (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)
@@ -402,9 +403,9 @@ const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
402
403
  default:
403
404
  throw new T("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
404
405
  }
405
- }, it = async (e, t, r, a, n) => {
406
+ }, ct = async (e, t, r, a, n) => {
406
407
  let s, o;
407
- const i = new Uint8Array(atob(r.replace(e, "")).split("").map((c) => c.charCodeAt(0)));
408
+ const c = new Uint8Array(atob(r.replace(e, "")).split("").map((i) => i.charCodeAt(0)));
408
409
  switch (a) {
409
410
  case "PS256":
410
411
  case "PS384":
@@ -438,18 +439,18 @@ const Ie = (e) => (e == null ? void 0 : e[Symbol.toStringTag]) === "KeyObject",
438
439
  case "ECDH-ES+A128KW":
439
440
  case "ECDH-ES+A192KW":
440
441
  case "ECDH-ES+A256KW": {
441
- const c = ue(i);
442
- s = c.startsWith("P-") ? { name: "ECDH", namedCurve: c } : { name: c }, o = [];
442
+ const i = ue(c);
443
+ s = i.startsWith("P-") ? { name: "ECDH", namedCurve: i } : { name: i }, o = [];
443
444
  break;
444
445
  }
445
446
  case "EdDSA":
446
- s = { name: ue(i) }, o = ["verify"];
447
+ s = { name: ue(c) }, o = ["verify"];
447
448
  break;
448
449
  default:
449
450
  throw new T('Invalid or unsupported "alg" (Algorithm) value');
450
451
  }
451
- return G.subtle.importKey(t, i, s, !1, o);
452
- }, ut = (e, t, r) => it(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
452
+ return G.subtle.importKey(t, c, s, !1, o);
453
+ }, ut = (e, t, r) => ct(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", e, t);
453
454
  async function dt(e, t, r) {
454
455
  if (e.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
455
456
  throw new TypeError('"spki" must be SPKI formatted string');
@@ -525,16 +526,16 @@ function mt(e, t) {
525
526
  }
526
527
  }
527
528
  async function wt(e, t, r) {
528
- if (t = await ct.normalizePublicKey(t, e), Ae(t))
529
+ if (t = await it.normalizePublicKey(t, e), Ae(t))
529
530
  return Ze(t, e, r), t;
530
531
  if (t instanceof Uint8Array) {
531
532
  if (!e.startsWith("HS"))
532
- throw new TypeError(ie(t, ...Y));
533
+ throw new TypeError(ce(t, ...Y));
533
534
  return G.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
534
535
  }
535
- throw new TypeError(ie(t, ...Y, "Uint8Array"));
536
+ throw new TypeError(ce(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 w = M(e.protected);
565
+ a = JSON.parse(q.decode(w));
565
566
  } catch {
566
567
  throw new h("JWS Protected Header is invalid");
567
568
  }
@@ -574,11 +575,11 @@ async function Et(e, t, r) {
574
575
  let o = !0;
575
576
  if (s.has("b64") && (o = a.b64, typeof o != "boolean"))
576
577
  throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
577
- const { alg: i } = n;
578
- if (typeof i != "string" || !i)
578
+ const { alg: c } = n;
579
+ if (typeof c != "string" || !c)
579
580
  throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');
580
- const c = r && ft("algorithms", r.algorithms);
581
- if (c && !c.has(i))
581
+ const i = r && ft("algorithms", r.algorithms);
582
+ if (i && !i.has(c))
582
583
  throw new qe('"alg" (Algorithm) Header Parameter value not allowed');
583
584
  if (o) {
584
585
  if (typeof e.payload != "string")
@@ -586,15 +587,15 @@ async function Et(e, t, r) {
586
587
  } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
587
588
  throw new h("JWS Payload must be a string or an Uint8Array instance");
588
589
  let u = !1;
589
- 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;
590
+ typeof t == "function" && (t = await t(a, e), u = !0), pt(c, t, "verify");
591
+ const m = 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(c, t, y, m))
598
599
  throw new ze();
599
600
  let _;
600
601
  if (o)
@@ -604,9 +605,9 @@ 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
- const S = { payload: _ };
609
- return e.protected !== void 0 && (S.protectedHeader = a), e.header !== void 0 && (S.unprotectedHeader = e.header), u ? { ...S, key: t } : S;
608
+ typeof e.payload == "string" ? _ = N.encode(e.payload) : _ = e.payload;
609
+ const E = { payload: _ };
610
+ return e.protected !== void 0 && (E.protectedHeader = a), e.header !== void 0 && (E.unprotectedHeader = e.header), u ? { ...E, key: t } : E;
610
611
  }
611
612
  async function gt(e, t, r) {
612
613
  if (e instanceof Uint8Array && (e = q.decode(e)), typeof e != "string")
@@ -614,8 +615,8 @@ 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
- return typeof t == "function" ? { ...c, key: i.key } : c;
618
+ const c = await St({ payload: n, protected: a, signature: s }, t, r), i = { payload: c.payload, protectedHeader: c.protectedHeader };
619
+ return typeof t == "function" ? { ...i, key: c.key } : i;
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) => {
621
622
  const t = vt.exec(e);
@@ -671,56 +672,56 @@ const At = (e) => Math.floor(e.getTime() / 1e3), Ce = 60, Pe = Ce * 60, oe = Pe
671
672
  const { typ: n } = r;
672
673
  if (n && (typeof e.typ != "string" || le(e.typ) !== le(n)))
673
674
  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");
675
+ const { requiredClaims: s = [], issuer: o, subject: c, audience: i, maxTokenAge: u } = r, m = [...s];
676
+ u !== void 0 && m.push("iat"), i !== void 0 && m.push("aud"), c !== void 0 && m.push("sub"), o !== void 0 && m.push("iss");
677
+ for (const w of new Set(m.reverse()))
678
+ if (!(w in a))
679
+ throw new g(`missing required "${w}" claim`, a, w, "missing");
679
680
  if (o && !(Array.isArray(o) ? o : [o]).includes(a.iss))
680
681
  throw new g('unexpected "iss" claim value', a, "iss", "check_failed");
681
- if (i && a.sub !== i)
682
+ if (c && a.sub !== c)
682
683
  throw new g('unexpected "sub" claim value', a, "sub", "check_failed");
683
- if (c && !Tt(a.aud, typeof c == "string" ? [c] : c))
684
+ if (i && !Tt(a.aud, typeof i == "string" ? [i] : i))
684
685
  throw new g('unexpected "aud" claim value', a, "aud", "check_failed");
685
- let p;
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
- const { currentDate: _ } = r, S = At(_ || /* @__PURE__ */ new Date());
700
+ const { currentDate: _ } = r, E = At(_ || /* @__PURE__ */ new Date());
700
701
  if ((a.iat !== void 0 || u) && typeof a.iat != "number")
701
702
  throw new g('"iat" claim must be a number', a, "iat", "invalid");
702
703
  if (a.nbf !== void 0) {
703
704
  if (typeof a.nbf != "number")
704
705
  throw new g('"nbf" claim must be a number', a, "nbf", "invalid");
705
- if (a.nbf > S + p)
706
+ if (a.nbf > E + y)
706
707
  throw new g('"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
711
  throw new g('"exp" claim must be a number', a, "exp", "invalid");
711
- if (a.exp <= S - p)
712
- throw new ce('"exp" claim timestamp check failed', a, "exp", "check_failed");
712
+ if (a.exp <= E - y)
713
+ throw new ie('"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)
717
- throw new ce('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
718
- if (m < 0 - p)
716
+ const w = E - a.iat, k = typeof u == "number" ? u : de(u);
717
+ if (w - y > k)
718
+ throw new ie('"iat" claim timestamp check failed (too far in the past)', a, "iat", "check_failed");
719
+ if (w < 0 - y)
719
720
  throw new g('"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,7 +788,7 @@ 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({
@@ -798,12 +799,12 @@ function W({
798
799
  $t,
799
800
  r
800
801
  ), n = D.useCallback(
801
- (i) => {
802
+ (c) => {
802
803
  try {
803
- const c = typeof i == "function" ? i(JSON.parse(a)) : i;
804
- c == null ? Kt(e) : fe(e, c);
805
- } catch (c) {
806
- console.warn(c);
804
+ const i = typeof c == "function" ? c(JSON.parse(a)) : c;
805
+ i == null ? Nt(e) : fe(e, i);
806
+ } catch (i) {
807
+ console.warn(i);
807
808
  }
808
809
  },
809
810
  [e, a]
@@ -815,8 +816,8 @@ function W({
815
816
  return D.useEffect(() => {
816
817
  try {
817
818
  me(e) === null && typeof t < "u" && fe(e, t);
818
- } catch (i) {
819
- console.warn(i);
819
+ } catch (c) {
820
+ console.warn(c);
820
821
  }
821
822
  }, [e, t]), [a ? JSON.parse(a) : null, n, s, o];
822
823
  }
@@ -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.", U = "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",
@@ -906,10 +907,10 @@ const re = "Oops! It looks like your session has expired. For your security, ple
906
907
  type: n,
907
908
  sessionExpiration: s,
908
909
  code: o,
909
- code_verifier: i
910
+ code_verifier: c
910
911
  }) => {
911
912
  try {
912
- const c = await z({
913
+ const i = await z({
913
914
  type: F.AUTHENTICATE,
914
915
  clientId: r,
915
916
  params: {
@@ -919,14 +920,14 @@ const re = "Oops! It looks like your session has expired. For your security, ple
919
920
  sessionExpiration: s,
920
921
  nonce: a,
921
922
  code: o,
922
- code_verifier: i
923
+ code_verifier: c
923
924
  }
924
- }), u = await H(c.data.idToken);
925
- return u && u.payload[y.USER_ID_KEY] !== "" && u.payload[y.NONCE_KEY] === a ? {
926
- idToken: c.data.idToken,
927
- accessToken: c.data.accessToken,
928
- refreshToken: c.data.refreshToken,
929
- userId: u.payload[y.USER_ID_KEY],
925
+ }), u = await H(i.data.idToken);
926
+ return u && u.payload[f.USER_ID_KEY] !== "" && u.payload[f.NONCE_KEY] === a ? {
927
+ idToken: i.data.idToken,
928
+ accessToken: i.data.accessToken,
929
+ refreshToken: i.data.refreshToken,
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
@@ -1011,38 +1012,41 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1011
1012
  }) => {
1012
1013
  const [a, n, , s] = W({
1013
1014
  key: `${x}::${r}::@@user@@`
1014
- }), [o, i, , c] = W({
1015
+ }), [o, c, , i] = W({
1015
1016
  key: `${x}::${r}::@@access@@`
1016
- }), [u, f, , p] = W(
1017
+ }), [u, m, , y] = W(
1017
1018
  {
1018
1019
  key: `${x}::${r}::@@refresh@@`
1019
1020
  }
1020
- ), [_, S, , m] = W({
1021
+ ), [_, E, , w] = W({
1021
1022
  key: `${x}::${r}::@@nonce@@`
1022
- }), [k, N] = xe({
1023
+ }), [k, K] = xe({
1023
1024
  isLoading: !0,
1024
1025
  isAuthenticated: !1,
1025
- userId: "",
1026
+ user: void 0,
1026
1027
  logoutReason: ""
1027
1028
  }), A = je(
1028
- (w) => {
1029
- N({
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(), i(), y(), w();
1035
1036
  },
1036
- [s, c, m, p]
1037
+ [s, i, w, y]
1037
1038
  );
1038
1039
  Me(() => {
1039
1040
  k.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
1051
  }) : (A(re), await ae({
1048
1052
  idToken: a,
@@ -1067,47 +1071,53 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1067
1071
  r,
1068
1072
  A
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, R) => {
1075
+ const I = jt();
1076
+ if (E(I), R === B.CODE) {
1077
+ const { code_verifier: $e, code_challenge: Le } = await Kt(), se = await Ft({
1078
+ nonce: I,
1075
1079
  clientId: r,
1076
1080
  code_challenge: Le
1077
1081
  });
1078
1082
  if (se.status) {
1079
1083
  const O = await ge({
1080
- username: w,
1084
+ username: p,
1081
1085
  password: P,
1082
1086
  clientId: r,
1083
1087
  sessionExpiration: t,
1084
- nonce: R,
1085
- type: I,
1088
+ nonce: I,
1089
+ type: R,
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 O.status ? (n(O.idToken), c(O.accessToken), m(O.refreshToken), K({
1090
1094
  isLoading: !1,
1091
1095
  isAuthenticated: !0,
1092
- userId: O.userId,
1096
+ user: {
1097
+ userId: O.userId,
1098
+ username: p
1099
+ },
1093
1100
  logoutReason: ""
1094
- }), !0) : (A(Se), !1);
1101
+ }), !0) : (A(Ee), !1);
1095
1102
  }
1096
1103
  return !1;
1097
1104
  }
1098
- const E = await ge({
1099
- username: w,
1105
+ const S = await ge({
1106
+ username: p,
1100
1107
  password: P,
1101
1108
  clientId: r,
1102
1109
  sessionExpiration: t,
1103
- nonce: R,
1104
- type: I
1110
+ nonce: I,
1111
+ type: R
1105
1112
  });
1106
- return E.status ? (n(E.idToken), i(E.accessToken), f(E.refreshToken), N({
1113
+ return S.status ? (n(S.idToken), c(S.accessToken), m(S.refreshToken), K({
1107
1114
  isLoading: !1,
1108
1115
  isAuthenticated: !0,
1109
- userId: E.userId
1110
- }), !0) : (A(Se), !1);
1116
+ user: {
1117
+ userId: S.userId,
1118
+ username: p
1119
+ }
1120
+ }), !0) : (A(Ee), !1);
1111
1121
  }, He = async () => {
1112
1122
  A(Mt), await ae({
1113
1123
  idToken: a,
@@ -1115,24 +1125,24 @@ const re = "Oops! It looks like your session has expired. For your security, ple
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 } = k;
1120
1130
  try {
1121
- if (w && P && o) {
1122
- const I = await H(o);
1123
- if (I && I.payload[y.USER_ID_KEY] !== "")
1131
+ if (p && P && P.userId && o) {
1132
+ const R = await H(o);
1133
+ if (R && R.payload[f.USER_ID_KEY] !== "")
1124
1134
  return o;
1125
- const R = await H(u);
1126
- if (R && R.payload[y.USER_ID_KEY] !== "") {
1127
- const E = await Gt({
1135
+ const I = await H(u);
1136
+ if (I && I.payload[f.USER_ID_KEY] !== "") {
1137
+ const S = await Gt({
1128
1138
  clientId: r,
1129
- userId: P,
1139
+ userId: P.userId,
1130
1140
  nonce: _,
1131
1141
  refreshToken: u,
1132
1142
  accessToken: o
1133
1143
  });
1134
- if (E.status)
1135
- return i(E.accessToken), f(E.refreshToken), E.accessToken;
1144
+ if (S.status)
1145
+ return c(S.accessToken), m(S.refreshToken), S.accessToken;
1136
1146
  A(U);
1137
1147
  }
1138
1148
  return A(U), console.error(U), "";
@@ -1140,14 +1150,14 @@ const re = "Oops! It looks like your session has expired. For your security, ple
1140
1150
  } catch {
1141
1151
  return A(U), console.error(U), "";
1142
1152
  }
1143
- }, Ke = () => {
1153
+ }, Ne = () => {
1144
1154
  if (k.isAuthenticated && a)
1145
1155
  return a;
1146
1156
  };
1147
1157
  return /* @__PURE__ */ We(
1148
1158
  De.Provider,
1149
1159
  {
1150
- value: { ...k, login: Ue, logout: He, getAccessToken: Ne, getIdToken: Ke },
1160
+ value: { ...k, login: Ue, logout: He, getAccessToken: Ke, getIdToken: Ne },
1151
1161
  children: e
1152
1162
  }
1153
1163
  );
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.0",
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
49
  "jose": "5.6.2",
50
50
  "uuid": "10.0.0"
51
51
  },
52
- "gitHead": "5abd68fc5595a95360b4e80088cc39c067722085"
52
+ "gitHead": "5a4130a33944cf31fe9bd4dd32207119bc27678d"
53
53
  }