@orangecheck/auth-client 2.40.1 → 2.41.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.
Files changed (33) hide show
  1. package/README.md +4 -1
  2. package/dist/bond.mjs +4 -4
  3. package/dist/{chunk-S6YP5Q5X.mjs → chunk-47DAA4BV.mjs} +2 -2
  4. package/dist/{chunk-O45WZCJI.mjs → chunk-F7O4OREM.mjs} +2 -2
  5. package/dist/{chunk-JMXIH6AH.mjs → chunk-FMPBHB3Q.mjs} +2 -2
  6. package/dist/{chunk-FKROF5NN.mjs → chunk-JLMDCC6K.mjs} +24 -12
  7. package/dist/chunk-JLMDCC6K.mjs.map +1 -0
  8. package/dist/{chunk-A4A6OEVX.mjs → chunk-PQHFAVVM.mjs} +1 -1
  9. package/dist/chunk-PQHFAVVM.mjs.map +1 -0
  10. package/dist/{chunk-LA2VDQSE.mjs → chunk-PYQTVOVH.mjs} +25 -8
  11. package/dist/chunk-PYQTVOVH.mjs.map +1 -0
  12. package/dist/{chunk-IYK4KW6B.mjs → chunk-UBDRTV5O.mjs} +2 -2
  13. package/dist/{chunk-AIP3GYPO.mjs → chunk-Y2PA7VC5.mjs} +3 -3
  14. package/dist/components.mjs +3 -3
  15. package/dist/index.d.ts +11 -1
  16. package/dist/index.js +45 -16
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +8 -8
  19. package/dist/linked-identities.mjs +3 -3
  20. package/dist/provider.mjs +2 -2
  21. package/dist/signin.mjs +4 -4
  22. package/dist/sudo.mjs +2 -2
  23. package/dist/types.mjs +1 -1
  24. package/dist/webauthn.mjs +3 -3
  25. package/package.json +1 -1
  26. package/dist/chunk-A4A6OEVX.mjs.map +0 -1
  27. package/dist/chunk-FKROF5NN.mjs.map +0 -1
  28. package/dist/chunk-LA2VDQSE.mjs.map +0 -1
  29. /package/dist/{chunk-S6YP5Q5X.mjs.map → chunk-47DAA4BV.mjs.map} +0 -0
  30. /package/dist/{chunk-O45WZCJI.mjs.map → chunk-F7O4OREM.mjs.map} +0 -0
  31. /package/dist/{chunk-JMXIH6AH.mjs.map → chunk-FMPBHB3Q.mjs.map} +0 -0
  32. /package/dist/{chunk-IYK4KW6B.mjs.map → chunk-UBDRTV5O.mjs.map} +0 -0
  33. /package/dist/{chunk-AIP3GYPO.mjs.map → chunk-Y2PA7VC5.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -516,13 +516,14 @@ function OcSessionProvider({
516
516
  () => cfg.multiAccount ? installTabLinkDecorator(cfg.authOrigin) : void 0,
517
517
  [cfg.authOrigin, cfg.multiAccount]
518
518
  );
519
- const signOut = React4__namespace.useCallback(
519
+ const trySignOut = React4__namespace.useCallback(
520
520
  async (opts) => {
521
521
  const scope = opts?.scope ?? "all";
522
+ let res;
522
523
  try {
523
524
  const url = new URL(`${cfg.authOrigin}${cfg.logoutPath}`);
524
525
  if (scope === "current") url.searchParams.set("scope", "current");
525
- const res = await fetch(url.toString(), {
526
+ res = await fetch(url.toString(), {
526
527
  method: "POST",
527
528
  credentials: "include",
528
529
  // Per-tab · carry the pin so scope='current' signs out
@@ -536,22 +537,31 @@ function OcSessionProvider({
536
537
  // and the `.ochk.io` cookie may never get cleared.
537
538
  keepalive: true
538
539
  });
539
- clearTabSession();
540
- setTabPinned(false);
541
- if (scope === "current" && res.ok) {
542
- await refresh();
543
- return;
544
- }
545
540
  } catch {
546
- clearTabSession();
547
- setTabPinned(false);
541
+ return { ok: false, reason: "unreachable" };
542
+ }
543
+ if (!res.ok && res.status !== 401) {
544
+ return { ok: false, reason: "refused", status: res.status };
545
+ }
546
+ clearTabSession();
547
+ setTabPinned(false);
548
+ if (scope === "current" && res.ok) {
549
+ await refresh();
550
+ return { ok: true };
548
551
  }
549
552
  setAccount(null);
550
553
  setRoster([]);
551
554
  setStatus("anonymous");
555
+ return { ok: true };
552
556
  },
553
557
  [cfg.authOrigin, cfg.logoutPath, refresh]
554
558
  );
559
+ const signOut = React4__namespace.useCallback(
560
+ async (opts) => {
561
+ await trySignOut(opts);
562
+ },
563
+ [trySignOut]
564
+ );
555
565
  const switchAccount = React4__namespace.useCallback(
556
566
  async (didOc) => {
557
567
  if (typeof window === "undefined") return;
@@ -630,6 +640,7 @@ function OcSessionProvider({
630
640
  error,
631
641
  refresh,
632
642
  signOut,
643
+ trySignOut,
633
644
  switchAccount,
634
645
  addAccountUrl,
635
646
  setDisplayIdentity,
@@ -643,6 +654,7 @@ function OcSessionProvider({
643
654
  error,
644
655
  refresh,
645
656
  signOut,
657
+ trySignOut,
646
658
  switchAccount,
647
659
  addAccountUrl,
648
660
  setDisplayIdentity,
@@ -689,9 +701,10 @@ function OcAccountChip({
689
701
  popoverClassName,
690
702
  menuItemClassName
691
703
  }) {
692
- const { status, account, signInUrl: sessionSignInUrl, signOut } = useOcSession();
704
+ const { status, account, signInUrl: sessionSignInUrl, trySignOut } = useOcSession();
693
705
  const signInUrl = signInUrlOverride ?? sessionSignInUrl;
694
706
  const [open, setOpen] = React4__namespace.useState(false);
707
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
695
708
  const wrapRef = React4__namespace.useRef(null);
696
709
  React4__namespace.useEffect(() => {
697
710
  if (!open) return;
@@ -903,7 +916,8 @@ function OcAccountChip({
903
916
  role: "menuitem",
904
917
  onClick: () => {
905
918
  setOpen(false);
906
- void signOut();
919
+ setSignOutFailed(false);
920
+ void trySignOut().then((r) => setSignOutFailed(!r.ok));
907
921
  },
908
922
  className: menuItemClassName,
909
923
  "data-oc-account-chip-item": "",
@@ -938,11 +952,23 @@ function OcAccountChip({
938
952
  ] })
939
953
  ]
940
954
  }
941
- )
955
+ ),
956
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
942
957
  ]
943
958
  }
944
959
  );
945
960
  }
961
+ function SignOutFailed() {
962
+ return /* @__PURE__ */ jsxRuntime.jsx(
963
+ "span",
964
+ {
965
+ role: "alert",
966
+ "data-oc-signout-failed": "",
967
+ style: { display: "block", marginTop: 4, fontSize: 12, color: "var(--destructive, #dc2626)" },
968
+ children: "Couldn\u2019t sign out. You\u2019re still signed in; try again."
969
+ }
970
+ );
971
+ }
946
972
  function OcSignInButton({
947
973
  label = "sign in",
948
974
  eager = false,
@@ -971,7 +997,8 @@ function OcAccountPill({
971
997
  className,
972
998
  ...rest
973
999
  }) {
974
- const { status, account, signOut } = useOcSession();
1000
+ const { status, account, trySignOut } = useOcSession();
1001
+ const [signOutFailed, setSignOutFailed] = React4__namespace.useState(false);
975
1002
  if (status !== "authenticated" || !account) return null;
976
1003
  const label = render ? render({ address: account.didOc, displayName: account.displayName }) : account.displayName ?? shortenAddress(account.didOc);
977
1004
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -988,7 +1015,8 @@ function OcAccountPill({
988
1015
  {
989
1016
  type: "button",
990
1017
  onClick: () => {
991
- void signOut();
1018
+ setSignOutFailed(false);
1019
+ void trySignOut().then((r) => setSignOutFailed(!r.ok));
992
1020
  },
993
1021
  "aria-label": "Sign out",
994
1022
  style: {
@@ -1001,7 +1029,8 @@ function OcAccountPill({
1001
1029
  },
1002
1030
  children: "sign out"
1003
1031
  }
1004
- )
1032
+ ),
1033
+ signOutFailed ? /* @__PURE__ */ jsxRuntime.jsx(SignOutFailed, {}) : null
1005
1034
  ]
1006
1035
  }
1007
1036
  );