@hexdspace/react 0.0.20 → 0.0.22
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.ts +5 -2
- package/dist/index.js +29 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -363,15 +363,18 @@ type RequireAuthProps = {
|
|
|
363
363
|
guarded?: ReactNode;
|
|
364
364
|
loadingPlaceholder?: ReactNode;
|
|
365
365
|
errorPlaceholder?: ReactNode;
|
|
366
|
+
unauthenticatedRedirectTo?: string;
|
|
367
|
+
unauthenticatedPlaceholder?: ReactNode;
|
|
366
368
|
};
|
|
367
369
|
type RedirectIfAuthedProps = {
|
|
368
370
|
redirectTo?: string;
|
|
369
371
|
loadingPlaceholder?: ReactNode;
|
|
370
372
|
nonAuthedPlaceholder?: ReactNode;
|
|
371
373
|
errorPlaceholder?: ReactNode;
|
|
374
|
+
authenticatedPlaceholder?: ReactNode;
|
|
372
375
|
};
|
|
373
|
-
declare function RequireAuth({ guarded, loadingPlaceholder, errorPlaceholder }: RequireAuthProps): react_jsx_runtime.JSX.Element;
|
|
374
|
-
declare function RedirectIfAuthed({ redirectTo, loadingPlaceholder, nonAuthedPlaceholder, errorPlaceholder }: RedirectIfAuthedProps): react_jsx_runtime.JSX.Element;
|
|
376
|
+
declare function RequireAuth({ guarded, loadingPlaceholder, errorPlaceholder, unauthenticatedRedirectTo, unauthenticatedPlaceholder }: RequireAuthProps): react_jsx_runtime.JSX.Element;
|
|
377
|
+
declare function RedirectIfAuthed({ redirectTo, loadingPlaceholder, nonAuthedPlaceholder, errorPlaceholder, authenticatedPlaceholder }: RedirectIfAuthedProps): react_jsx_runtime.JSX.Element;
|
|
375
378
|
|
|
376
379
|
type AuthFixtures = {
|
|
377
380
|
meError?: HttpError;
|
package/dist/index.js
CHANGED
|
@@ -912,29 +912,52 @@ var AuthFormInputField = ({ id, label, type, value, onChange, placeholder, class
|
|
|
912
912
|
// src/feature/auth/interface/web/react/auth-route-guards.tsx
|
|
913
913
|
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
|
914
914
|
import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
|
|
915
|
-
function RequireAuth({
|
|
915
|
+
function RequireAuth({
|
|
916
|
+
guarded,
|
|
917
|
+
loadingPlaceholder,
|
|
918
|
+
errorPlaceholder,
|
|
919
|
+
unauthenticatedRedirectTo,
|
|
920
|
+
unauthenticatedPlaceholder
|
|
921
|
+
}) {
|
|
916
922
|
const auth = useAuth();
|
|
917
923
|
const location = useLocation();
|
|
918
924
|
if (auth.status === "loading") {
|
|
919
925
|
return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
|
|
920
926
|
}
|
|
921
927
|
if (auth.status === "error") {
|
|
922
|
-
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? loadingPlaceholder ?? null });
|
|
928
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? unauthenticatedPlaceholder ?? loadingPlaceholder ?? null });
|
|
923
929
|
}
|
|
924
930
|
if (auth.status === "unauthenticated") {
|
|
925
|
-
|
|
931
|
+
if (unauthenticatedRedirectTo) {
|
|
932
|
+
return /* @__PURE__ */ jsx6(Navigate, { to: unauthenticatedRedirectTo, replace: true, state: { from: location } });
|
|
933
|
+
}
|
|
934
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: unauthenticatedPlaceholder ?? null });
|
|
926
935
|
}
|
|
927
936
|
return guarded ? /* @__PURE__ */ jsx6(Fragment, { children: guarded }) : /* @__PURE__ */ jsx6(Outlet, {});
|
|
928
937
|
}
|
|
929
|
-
function RedirectIfAuthed({
|
|
938
|
+
function RedirectIfAuthed({
|
|
939
|
+
redirectTo,
|
|
940
|
+
loadingPlaceholder,
|
|
941
|
+
nonAuthedPlaceholder,
|
|
942
|
+
errorPlaceholder,
|
|
943
|
+
authenticatedPlaceholder
|
|
944
|
+
}) {
|
|
930
945
|
const auth = useAuth();
|
|
931
946
|
if (auth.status === "loading") {
|
|
932
947
|
return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
|
|
933
948
|
}
|
|
934
949
|
if (auth.status === "error") {
|
|
935
|
-
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? loadingPlaceholder ?? null });
|
|
950
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? nonAuthedPlaceholder ?? loadingPlaceholder ?? null });
|
|
951
|
+
}
|
|
952
|
+
if (auth.status === "authenticated") {
|
|
953
|
+
if (redirectTo) {
|
|
954
|
+
return /* @__PURE__ */ jsx6(Navigate, { to: redirectTo, replace: true });
|
|
955
|
+
}
|
|
956
|
+
if (authenticatedPlaceholder) {
|
|
957
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: authenticatedPlaceholder });
|
|
958
|
+
}
|
|
959
|
+
return /* @__PURE__ */ jsx6(Outlet, {});
|
|
936
960
|
}
|
|
937
|
-
if (auth.status === "authenticated") return /* @__PURE__ */ jsx6(Navigate, { to: redirectTo ?? "/", replace: true });
|
|
938
961
|
return nonAuthedPlaceholder ? /* @__PURE__ */ jsx6(Fragment, { children: nonAuthedPlaceholder }) : /* @__PURE__ */ jsx6(Outlet, {});
|
|
939
962
|
}
|
|
940
963
|
|