@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.d.mts CHANGED
@@ -41,6 +41,7 @@ declare class HttpClient {
41
41
  constructor(config?: HttpClientConfig);
42
42
  private buildURL;
43
43
  private request;
44
+ setOnUnauthorized(handler: (error: HttpError) => void): void;
44
45
  setDefaultHeader(key: string, value: string): void;
45
46
  removeDefaultHeader(key: string): void;
46
47
  getDefaultHeaders(): Record<string, string>;
@@ -230,9 +231,8 @@ declare class AuthService implements IAuthService {
230
231
  interface LoginCallbackPageProps {
231
232
  authService: IAuthService;
232
233
  navigateTo?: string;
233
- onLoginFailed?: () => void;
234
234
  }
235
- declare function LoginCallbackPage({ authService, navigateTo, onLoginFailed }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
235
+ declare function LoginCallbackPage({ authService, navigateTo }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
236
236
 
237
237
  interface ProtectedRouteProps {
238
238
  children: ReactElement;
package/dist/index.d.ts CHANGED
@@ -41,6 +41,7 @@ declare class HttpClient {
41
41
  constructor(config?: HttpClientConfig);
42
42
  private buildURL;
43
43
  private request;
44
+ setOnUnauthorized(handler: (error: HttpError) => void): void;
44
45
  setDefaultHeader(key: string, value: string): void;
45
46
  removeDefaultHeader(key: string): void;
46
47
  getDefaultHeaders(): Record<string, string>;
@@ -230,9 +231,8 @@ declare class AuthService implements IAuthService {
230
231
  interface LoginCallbackPageProps {
231
232
  authService: IAuthService;
232
233
  navigateTo?: string;
233
- onLoginFailed?: () => void;
234
234
  }
235
- declare function LoginCallbackPage({ authService, navigateTo, onLoginFailed }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
235
+ declare function LoginCallbackPage({ authService, navigateTo }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
236
236
 
237
237
  interface ProtectedRouteProps {
238
238
  children: ReactElement;
package/dist/index.js CHANGED
@@ -659,6 +659,9 @@ var HttpClient = class {
659
659
  throw error;
660
660
  }
661
661
  }
662
+ setOnUnauthorized(handler) {
663
+ this.onUnauthorized = handler;
664
+ }
662
665
  setDefaultHeader(key, value) {
663
666
  this.defaultHeaders[key] = value;
664
667
  }
@@ -694,25 +697,27 @@ function extractErrorMessage(error) {
694
697
  }
695
698
  return "An unexpected error occurred";
696
699
  }
697
- function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
700
+ function LoginCallbackPage({ authService, navigateTo = "/" }) {
698
701
  const [searchParams] = reactRouterDom.useSearchParams();
699
702
  const navigate = reactRouterDom.useNavigate();
700
703
  const { theme } = useTheme();
704
+ const [error, setError] = react.useState(null);
701
705
  react.useEffect(() => {
702
706
  const loginToken = searchParams.get("login_token");
703
707
  if (!loginToken) {
704
708
  console.error("Login callback failed: Missing login_token in query parameters");
705
- onLoginFailed?.();
709
+ setError("Login failed: missing login token.");
706
710
  return;
707
711
  }
708
712
  authService.signInWithLoginToken({ loginToken, includePermissions: true }).then(() => {
709
713
  navigate(navigateTo, { replace: true });
710
714
  }).catch((err) => {
711
- console.error("Login callback failed:", extractErrorMessage(err));
712
- onLoginFailed?.();
715
+ const message = extractErrorMessage(err);
716
+ console.error("Login callback failed:", message);
717
+ setError(message);
713
718
  });
714
719
  }, []);
715
- return /* @__PURE__ */ jsxRuntime.jsxs(
720
+ return /* @__PURE__ */ jsxRuntime.jsx(
716
721
  material.Box,
717
722
  {
718
723
  sx: {
@@ -724,10 +729,25 @@ function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
724
729
  background: `linear-gradient(135deg, ${theme.colors.primary} 0%, ${theme.colors.primaryActive} 100%)`,
725
730
  gap: 2
726
731
  },
727
- children: [
732
+ children: error ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
733
+ /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body1", sx: { color: theme.colors.surface, fontWeight: 500 }, children: error }),
734
+ /* @__PURE__ */ jsxRuntime.jsx(
735
+ material.Button,
736
+ {
737
+ variant: "contained",
738
+ onClick: () => navigate(navigateTo, { replace: true }),
739
+ sx: {
740
+ backgroundColor: theme.colors.surface,
741
+ color: theme.colors.primary,
742
+ "&:hover": { backgroundColor: theme.colors.surface, opacity: 0.9 }
743
+ },
744
+ children: "Retry"
745
+ }
746
+ )
747
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
728
748
  /* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, { sx: { color: theme.colors.surface } }),
729
749
  /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body2", sx: { color: theme.colors.surface, opacity: 0.85 }, children: "Signing you in\u2026" })
730
- ]
750
+ ] })
731
751
  }
732
752
  );
733
753
  }