@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.d.mts
CHANGED
|
@@ -10,6 +10,7 @@ interface HttpClientConfig {
|
|
|
10
10
|
baseURL?: string;
|
|
11
11
|
timeout?: number;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
|
+
onUnauthorized?: (error: HttpError) => void;
|
|
13
14
|
}
|
|
14
15
|
interface RequestConfig extends Omit<RequestInit, 'body'> {
|
|
15
16
|
params?: Record<string, string | number | boolean>;
|
|
@@ -36,6 +37,7 @@ declare class HttpClient {
|
|
|
36
37
|
private baseURL;
|
|
37
38
|
private timeout;
|
|
38
39
|
private defaultHeaders;
|
|
40
|
+
private onUnauthorized?;
|
|
39
41
|
constructor(config?: HttpClientConfig);
|
|
40
42
|
private buildURL;
|
|
41
43
|
private request;
|
|
@@ -228,9 +230,8 @@ declare class AuthService implements IAuthService {
|
|
|
228
230
|
interface LoginCallbackPageProps {
|
|
229
231
|
authService: IAuthService;
|
|
230
232
|
navigateTo?: string;
|
|
231
|
-
onLoginFailed?: () => void;
|
|
232
233
|
}
|
|
233
|
-
declare function LoginCallbackPage({ authService, navigateTo
|
|
234
|
+
declare function LoginCallbackPage({ authService, navigateTo }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
|
|
234
235
|
|
|
235
236
|
interface ProtectedRouteProps {
|
|
236
237
|
children: ReactElement;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ interface HttpClientConfig {
|
|
|
10
10
|
baseURL?: string;
|
|
11
11
|
timeout?: number;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
|
+
onUnauthorized?: (error: HttpError) => void;
|
|
13
14
|
}
|
|
14
15
|
interface RequestConfig extends Omit<RequestInit, 'body'> {
|
|
15
16
|
params?: Record<string, string | number | boolean>;
|
|
@@ -36,6 +37,7 @@ declare class HttpClient {
|
|
|
36
37
|
private baseURL;
|
|
37
38
|
private timeout;
|
|
38
39
|
private defaultHeaders;
|
|
40
|
+
private onUnauthorized?;
|
|
39
41
|
constructor(config?: HttpClientConfig);
|
|
40
42
|
private buildURL;
|
|
41
43
|
private request;
|
|
@@ -228,9 +230,8 @@ declare class AuthService implements IAuthService {
|
|
|
228
230
|
interface LoginCallbackPageProps {
|
|
229
231
|
authService: IAuthService;
|
|
230
232
|
navigateTo?: string;
|
|
231
|
-
onLoginFailed?: () => void;
|
|
232
233
|
}
|
|
233
|
-
declare function LoginCallbackPage({ authService, navigateTo
|
|
234
|
+
declare function LoginCallbackPage({ authService, navigateTo }: LoginCallbackPageProps): react_jsx_runtime.JSX.Element;
|
|
234
235
|
|
|
235
236
|
interface ProtectedRouteProps {
|
|
236
237
|
children: ReactElement;
|
package/dist/index.js
CHANGED
|
@@ -603,6 +603,7 @@ var HttpClient = class {
|
|
|
603
603
|
this.baseURL = config.baseURL || "";
|
|
604
604
|
this.timeout = config.timeout || 3e4;
|
|
605
605
|
this.defaultHeaders = config.headers || {};
|
|
606
|
+
this.onUnauthorized = config.onUnauthorized;
|
|
606
607
|
}
|
|
607
608
|
buildURL(url, params) {
|
|
608
609
|
const fullURL = url.startsWith("http") ? url : `${this.baseURL}${url}`;
|
|
@@ -638,6 +639,9 @@ var HttpClient = class {
|
|
|
638
639
|
} catch {
|
|
639
640
|
error.data = { code: response.status, message: await response.text() };
|
|
640
641
|
}
|
|
642
|
+
if (response.status === 401 && this.onUnauthorized) {
|
|
643
|
+
this.onUnauthorized(error);
|
|
644
|
+
}
|
|
641
645
|
throw error;
|
|
642
646
|
}
|
|
643
647
|
const responseData = await response.json();
|
|
@@ -690,25 +694,27 @@ function extractErrorMessage(error) {
|
|
|
690
694
|
}
|
|
691
695
|
return "An unexpected error occurred";
|
|
692
696
|
}
|
|
693
|
-
function LoginCallbackPage({ authService, navigateTo = "/"
|
|
697
|
+
function LoginCallbackPage({ authService, navigateTo = "/" }) {
|
|
694
698
|
const [searchParams] = reactRouterDom.useSearchParams();
|
|
695
699
|
const navigate = reactRouterDom.useNavigate();
|
|
696
700
|
const { theme } = useTheme();
|
|
701
|
+
const [error, setError] = react.useState(null);
|
|
697
702
|
react.useEffect(() => {
|
|
698
703
|
const loginToken = searchParams.get("login_token");
|
|
699
704
|
if (!loginToken) {
|
|
700
705
|
console.error("Login callback failed: Missing login_token in query parameters");
|
|
701
|
-
|
|
706
|
+
setError("Login failed: missing login token.");
|
|
702
707
|
return;
|
|
703
708
|
}
|
|
704
709
|
authService.signInWithLoginToken({ loginToken, includePermissions: true }).then(() => {
|
|
705
710
|
navigate(navigateTo, { replace: true });
|
|
706
711
|
}).catch((err) => {
|
|
707
|
-
|
|
708
|
-
|
|
712
|
+
const message = extractErrorMessage(err);
|
|
713
|
+
console.error("Login callback failed:", message);
|
|
714
|
+
setError(message);
|
|
709
715
|
});
|
|
710
716
|
}, []);
|
|
711
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
717
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
712
718
|
material.Box,
|
|
713
719
|
{
|
|
714
720
|
sx: {
|
|
@@ -720,10 +726,25 @@ function LoginCallbackPage({ authService, navigateTo = "/", onLoginFailed }) {
|
|
|
720
726
|
background: `linear-gradient(135deg, ${theme.colors.primary} 0%, ${theme.colors.primaryActive} 100%)`,
|
|
721
727
|
gap: 2
|
|
722
728
|
},
|
|
723
|
-
children: [
|
|
729
|
+
children: error ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
730
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body1", sx: { color: theme.colors.surface, fontWeight: 500 }, children: error }),
|
|
731
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
732
|
+
material.Button,
|
|
733
|
+
{
|
|
734
|
+
variant: "contained",
|
|
735
|
+
onClick: () => navigate(navigateTo, { replace: true }),
|
|
736
|
+
sx: {
|
|
737
|
+
backgroundColor: theme.colors.surface,
|
|
738
|
+
color: theme.colors.primary,
|
|
739
|
+
"&:hover": { backgroundColor: theme.colors.surface, opacity: 0.9 }
|
|
740
|
+
},
|
|
741
|
+
children: "Retry"
|
|
742
|
+
}
|
|
743
|
+
)
|
|
744
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
724
745
|
/* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, { sx: { color: theme.colors.surface } }),
|
|
725
746
|
/* @__PURE__ */ jsxRuntime.jsx(material.Typography, { variant: "body2", sx: { color: theme.colors.surface, opacity: 0.85 }, children: "Signing you in\u2026" })
|
|
726
|
-
]
|
|
747
|
+
] })
|
|
727
748
|
}
|
|
728
749
|
);
|
|
729
750
|
}
|