@gofreego/tsutils 0.1.21 → 0.1.23
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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -590,6 +590,7 @@ var HttpClient = class {
|
|
|
590
590
|
this.baseURL = config.baseURL || "";
|
|
591
591
|
this.timeout = config.timeout || 3e4;
|
|
592
592
|
this.defaultHeaders = config.headers || {};
|
|
593
|
+
this.onUnauthorized = config.onUnauthorized;
|
|
593
594
|
}
|
|
594
595
|
buildURL(url, params) {
|
|
595
596
|
const fullURL = url.startsWith("http") ? url : `${this.baseURL}${url}`;
|
|
@@ -625,6 +626,9 @@ var HttpClient = class {
|
|
|
625
626
|
} catch {
|
|
626
627
|
error.data = { code: response.status, message: await response.text() };
|
|
627
628
|
}
|
|
629
|
+
if (response.status === 401 && this.onUnauthorized) {
|
|
630
|
+
this.onUnauthorized(error);
|
|
631
|
+
}
|
|
628
632
|
throw error;
|
|
629
633
|
}
|
|
630
634
|
const responseData = await response.json();
|
|
@@ -677,25 +681,27 @@ function extractErrorMessage(error) {
|
|
|
677
681
|
}
|
|
678
682
|
return "An unexpected error occurred";
|
|
679
683
|
}
|
|
680
|
-
function LoginCallbackPage({ authService, navigateTo = "/"
|
|
684
|
+
function LoginCallbackPage({ authService, navigateTo = "/" }) {
|
|
681
685
|
const [searchParams] = useSearchParams();
|
|
682
686
|
const navigate = useNavigate();
|
|
683
687
|
const { theme } = useTheme();
|
|
688
|
+
const [error, setError] = useState(null);
|
|
684
689
|
useEffect(() => {
|
|
685
690
|
const loginToken = searchParams.get("login_token");
|
|
686
691
|
if (!loginToken) {
|
|
687
692
|
console.error("Login callback failed: Missing login_token in query parameters");
|
|
688
|
-
|
|
693
|
+
setError("Login failed: missing login token.");
|
|
689
694
|
return;
|
|
690
695
|
}
|
|
691
696
|
authService.signInWithLoginToken({ loginToken, includePermissions: true }).then(() => {
|
|
692
697
|
navigate(navigateTo, { replace: true });
|
|
693
698
|
}).catch((err) => {
|
|
694
|
-
|
|
695
|
-
|
|
699
|
+
const message = extractErrorMessage(err);
|
|
700
|
+
console.error("Login callback failed:", message);
|
|
701
|
+
setError(message);
|
|
696
702
|
});
|
|
697
703
|
}, []);
|
|
698
|
-
return /* @__PURE__ */
|
|
704
|
+
return /* @__PURE__ */ jsx(
|
|
699
705
|
Box,
|
|
700
706
|
{
|
|
701
707
|
sx: {
|
|
@@ -707,10 +713,25 @@ function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
|
|
|
707
713
|
background: `linear-gradient(135deg, ${theme.colors.primary} 0%, ${theme.colors.primaryActive} 100%)`,
|
|
708
714
|
gap: 2
|
|
709
715
|
},
|
|
710
|
-
children: [
|
|
716
|
+
children: error ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
717
|
+
/* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { color: theme.colors.surface, fontWeight: 500 }, children: error }),
|
|
718
|
+
/* @__PURE__ */ jsx(
|
|
719
|
+
Button,
|
|
720
|
+
{
|
|
721
|
+
variant: "contained",
|
|
722
|
+
onClick: () => navigate(navigateTo, { replace: true }),
|
|
723
|
+
sx: {
|
|
724
|
+
backgroundColor: theme.colors.surface,
|
|
725
|
+
color: theme.colors.primary,
|
|
726
|
+
"&:hover": { backgroundColor: theme.colors.surface, opacity: 0.9 }
|
|
727
|
+
},
|
|
728
|
+
children: "Retry"
|
|
729
|
+
}
|
|
730
|
+
)
|
|
731
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
711
732
|
/* @__PURE__ */ jsx(CircularProgress, { sx: { color: theme.colors.surface } }),
|
|
712
733
|
/* @__PURE__ */ jsx(Typography, { variant: "body2", sx: { color: theme.colors.surface, opacity: 0.85 }, children: "Signing you in\u2026" })
|
|
713
|
-
]
|
|
734
|
+
] })
|
|
714
735
|
}
|
|
715
736
|
);
|
|
716
737
|
}
|