@gofreego/tsutils 0.1.22 → 0.1.24

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.mjs CHANGED
@@ -646,6 +646,9 @@ var HttpClient = class {
646
646
  throw error;
647
647
  }
648
648
  }
649
+ setOnUnauthorized(handler) {
650
+ this.onUnauthorized = handler;
651
+ }
649
652
  setDefaultHeader(key, value) {
650
653
  this.defaultHeaders[key] = value;
651
654
  }
@@ -681,25 +684,27 @@ function extractErrorMessage(error) {
681
684
  }
682
685
  return "An unexpected error occurred";
683
686
  }
684
- function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
687
+ function LoginCallbackPage({ authService, navigateTo = "/" }) {
685
688
  const [searchParams] = useSearchParams();
686
689
  const navigate = useNavigate();
687
690
  const { theme } = useTheme();
691
+ const [error, setError] = useState(null);
688
692
  useEffect(() => {
689
693
  const loginToken = searchParams.get("login_token");
690
694
  if (!loginToken) {
691
695
  console.error("Login callback failed: Missing login_token in query parameters");
692
- onLoginFailed?.();
696
+ setError("Login failed: missing login token.");
693
697
  return;
694
698
  }
695
699
  authService.signInWithLoginToken({ loginToken, includePermissions: true }).then(() => {
696
700
  navigate(navigateTo, { replace: true });
697
701
  }).catch((err) => {
698
- console.error("Login callback failed:", extractErrorMessage(err));
699
- onLoginFailed?.();
702
+ const message = extractErrorMessage(err);
703
+ console.error("Login callback failed:", message);
704
+ setError(message);
700
705
  });
701
706
  }, []);
702
- return /* @__PURE__ */ jsxs(
707
+ return /* @__PURE__ */ jsx(
703
708
  Box,
704
709
  {
705
710
  sx: {
@@ -711,10 +716,25 @@ function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
711
716
  background: `linear-gradient(135deg, ${theme.colors.primary} 0%, ${theme.colors.primaryActive} 100%)`,
712
717
  gap: 2
713
718
  },
714
- children: [
719
+ children: error ? /* @__PURE__ */ jsxs(Fragment, { children: [
720
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { color: theme.colors.surface, fontWeight: 500 }, children: error }),
721
+ /* @__PURE__ */ jsx(
722
+ Button,
723
+ {
724
+ variant: "contained",
725
+ onClick: () => navigate(navigateTo, { replace: true }),
726
+ sx: {
727
+ backgroundColor: theme.colors.surface,
728
+ color: theme.colors.primary,
729
+ "&:hover": { backgroundColor: theme.colors.surface, opacity: 0.9 }
730
+ },
731
+ children: "Retry"
732
+ }
733
+ )
734
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
715
735
  /* @__PURE__ */ jsx(CircularProgress, { sx: { color: theme.colors.surface } }),
716
736
  /* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: theme.colors.surface, opacity: 0.85 }, children: "Signing you in\u2026" })
717
- ]
737
+ ] })
718
738
  }
719
739
  );
720
740
  }