@hexdspace/react 0.0.13 → 0.0.15
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 +15 -1
- package/dist/index.js +31 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -356,6 +356,20 @@ interface InputProps {
|
|
|
356
356
|
}
|
|
357
357
|
declare const AuthFormInputField: react__default.FC<InputProps>;
|
|
358
358
|
|
|
359
|
+
type RequireAuthProps = {
|
|
360
|
+
guarded?: ReactNode;
|
|
361
|
+
loadingPlaceholder?: ReactNode;
|
|
362
|
+
errorPlaceholder?: ReactNode;
|
|
363
|
+
};
|
|
364
|
+
type RedirectIfAuthedProps = {
|
|
365
|
+
redirectTo?: string;
|
|
366
|
+
loadingPlaceholder?: ReactNode;
|
|
367
|
+
nonAuthedPlaceholder?: ReactNode;
|
|
368
|
+
errorPlaceholder?: ReactNode;
|
|
369
|
+
};
|
|
370
|
+
declare function RequireAuth({ guarded, loadingPlaceholder, errorPlaceholder }: RequireAuthProps): react_jsx_runtime.JSX.Element;
|
|
371
|
+
declare function RedirectIfAuthed({ redirectTo, loadingPlaceholder, nonAuthedPlaceholder, errorPlaceholder }: RedirectIfAuthedProps): react_jsx_runtime.JSX.Element;
|
|
372
|
+
|
|
359
373
|
type AuthFixtures = {
|
|
360
374
|
meError?: HttpError;
|
|
361
375
|
loginError?: HttpError;
|
|
@@ -375,4 +389,4 @@ declare class MockAuthHttpClient extends MockHttpClient {
|
|
|
375
389
|
private registerAuthRoutes;
|
|
376
390
|
}
|
|
377
391
|
|
|
378
|
-
export { AuthController, AuthControllerCtx, type AuthControllerDeps, AuthControllerProvider, AuthDispatchCtx, AuthFormInputField, AuthProvider, type AuthState, AuthStateCtx, type CacheInstruction, type CustomInstruction, DEFAULT_NOTIFICATION_CHANNEL, type ErrorResponse, type GenericResponse, HttpError, type HttpResponse, type Instruction, type InstructionContext, MockAuthHttpClient, MockHttpClient, type Notification, type NotificationAction, NotificationHost, type NotificationInstruction, type NotificationVariant, NotifierController, type OptimisticSnapshot, type ResolvedToastTheme, type ResponsiveMutation, type ToastActionTheme, type ToastTheme, type ToastTransition, type ToastifyCSSVars, type UIFail, type UIOk, type UIResult, type User, authController, controllerFactory, createAuthController, httpClient as fetchHttpClient, notifierController, resolveToastTheme, ui, useAuth, useAuthActions, useAuthController, useAuthDispatch, useAuthedUser, useResponsiveMutation };
|
|
392
|
+
export { AuthController, AuthControllerCtx, type AuthControllerDeps, AuthControllerProvider, AuthDispatchCtx, AuthFormInputField, AuthProvider, type AuthState, AuthStateCtx, type CacheInstruction, type CustomInstruction, DEFAULT_NOTIFICATION_CHANNEL, type ErrorResponse, type GenericResponse, type HttpClient, HttpError, type HttpMethod, type HttpResponse, type Instruction, type InstructionContext, MockAuthHttpClient, MockHttpClient, type Notification, type NotificationAction, NotificationHost, type NotificationInstruction, type NotificationVariant, NotifierController, type OptimisticSnapshot, RedirectIfAuthed, type RedirectIfAuthedProps, type RequestConfig, RequireAuth, type RequireAuthProps, type ResolvedToastTheme, type ResponsiveMutation, type ToastActionTheme, type ToastTheme, type ToastTransition, type ToastifyCSSVars, type UIFail, type UIOk, type UIResult, type User, authController, controllerFactory, createAuthController, httpClient as fetchHttpClient, notifierController, resolveToastTheme, ui, useAuth, useAuthActions, useAuthController, useAuthDispatch, useAuthedUser, useResponsiveMutation };
|
package/dist/index.js
CHANGED
|
@@ -921,6 +921,35 @@ var AuthFormInputField = ({ id, label, type, value, onChange, placeholder, class
|
|
|
921
921
|
] });
|
|
922
922
|
};
|
|
923
923
|
|
|
924
|
+
// src/feature/auth/interface/web/react/auth-route-guards.tsx
|
|
925
|
+
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
|
926
|
+
import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
|
|
927
|
+
function RequireAuth({ guarded, loadingPlaceholder, errorPlaceholder }) {
|
|
928
|
+
const auth = useAuth();
|
|
929
|
+
const location = useLocation();
|
|
930
|
+
if (auth.status === "loading") {
|
|
931
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
|
|
932
|
+
}
|
|
933
|
+
if (auth.status === "error") {
|
|
934
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? loadingPlaceholder ?? null });
|
|
935
|
+
}
|
|
936
|
+
if (auth.status === "unauthenticated") {
|
|
937
|
+
return /* @__PURE__ */ jsx6(Navigate, { to: "/login", replace: true, state: { from: location } });
|
|
938
|
+
}
|
|
939
|
+
return guarded ? /* @__PURE__ */ jsx6(Fragment, { children: guarded }) : /* @__PURE__ */ jsx6(Outlet, {});
|
|
940
|
+
}
|
|
941
|
+
function RedirectIfAuthed({ redirectTo, loadingPlaceholder, nonAuthedPlaceholder, errorPlaceholder }) {
|
|
942
|
+
const auth = useAuth();
|
|
943
|
+
if (auth.status === "loading") {
|
|
944
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: loadingPlaceholder ?? null });
|
|
945
|
+
}
|
|
946
|
+
if (auth.status === "error") {
|
|
947
|
+
return /* @__PURE__ */ jsx6(Fragment, { children: errorPlaceholder ?? loadingPlaceholder ?? null });
|
|
948
|
+
}
|
|
949
|
+
if (auth.status === "authenticated") return /* @__PURE__ */ jsx6(Navigate, { to: redirectTo ?? "/", replace: true });
|
|
950
|
+
return nonAuthedPlaceholder ? /* @__PURE__ */ jsx6(Fragment, { children: nonAuthedPlaceholder }) : /* @__PURE__ */ jsx6(Outlet, {});
|
|
951
|
+
}
|
|
952
|
+
|
|
924
953
|
// src/feature/auth/infra/mock-auth-http-client.ts
|
|
925
954
|
function httpResponse(data, status = 200) {
|
|
926
955
|
return { data, status, headers: {} };
|
|
@@ -1006,6 +1035,8 @@ export {
|
|
|
1006
1035
|
MockHttpClient,
|
|
1007
1036
|
NotificationHost,
|
|
1008
1037
|
NotifierController,
|
|
1038
|
+
RedirectIfAuthed,
|
|
1039
|
+
RequireAuth,
|
|
1009
1040
|
authController,
|
|
1010
1041
|
controllerFactory,
|
|
1011
1042
|
createAuthController,
|