@donotdev/ui 0.1.0 → 0.1.1
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/{GoToDialog-CR4VOVXT.js → GoToDialog-RU5RP7S2.js} +1 -1
- package/dist/chunk-ETE4RC7M.js +1 -0
- package/dist/components/auth/AuthHeader.d.ts +6 -1
- package/dist/components/auth/AuthHeader.d.ts.map +1 -1
- package/dist/components/auth/AuthHeader.js +4 -4
- package/dist/components/common/FeatureCard.d.ts +2 -0
- package/dist/components/common/FeatureCard.d.ts.map +1 -1
- package/dist/components/common/FeatureDisabled.d.ts +1 -0
- package/dist/components/common/FeatureDisabled.d.ts.map +1 -1
- package/dist/components/common/TechBento.d.ts +1 -0
- package/dist/components/common/TechBento.d.ts.map +1 -1
- package/dist/components/common/icon.d.ts +1 -0
- package/dist/components/common/icon.d.ts.map +1 -1
- package/dist/components/cookie-consent/CookieConsent.d.ts +1 -0
- package/dist/components/cookie-consent/CookieConsent.d.ts.map +1 -1
- package/dist/components/layout/PageConfig.d.ts +25 -0
- package/dist/components/layout/PageConfig.d.ts.map +1 -0
- package/dist/components/layout/PageConfig.js +47 -0
- package/dist/components/layout/components/Breadcrumbs.d.ts +2 -0
- package/dist/components/layout/components/Breadcrumbs.d.ts.map +1 -1
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts +1 -0
- package/dist/components/layout/components/FloatingLanguageSwitcher.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppBranding.d.ts +1 -0
- package/dist/components/layout/components/header/AppBranding.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppIcon.d.ts +1 -0
- package/dist/components/layout/components/header/AppIcon.d.ts.map +1 -1
- package/dist/components/layout/components/header/AppTitle.d.ts +1 -0
- package/dist/components/layout/components/header/AppTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/CacheSettings.js +2 -2
- package/dist/components/layout/components/header/GameTitle.d.ts +1 -0
- package/dist/components/layout/components/header/GameTitle.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderMenu.d.ts +1 -0
- package/dist/components/layout/components/header/HeaderMenu.d.ts.map +1 -1
- package/dist/components/layout/components/header/HeaderNavigation.d.ts +1 -0
- package/dist/components/layout/components/header/HeaderNavigation.d.ts.map +1 -1
- package/dist/components/layout/components/header/SettingsMenu.d.ts +1 -0
- package/dist/components/layout/components/header/SettingsMenu.d.ts.map +1 -1
- package/dist/components/layout/index.d.ts +1 -0
- package/dist/components/layout/index.d.ts.map +1 -1
- package/dist/components/layout/index.js +1 -0
- package/dist/crud/components/EntityCardList.d.ts +1 -1
- package/dist/crud/components/EntityCardList.d.ts.map +1 -1
- package/dist/crud/components/EntityCardList.js +32 -21
- package/dist/crud/components/EntityDisplayRenderer.d.ts +1 -1
- package/dist/crud/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityDisplayRenderer.js +13 -12
- package/dist/crud/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/crud/components/EntityFormRenderer.js +16 -18
- package/dist/crud/components/EntityList.d.ts +1 -1
- package/dist/crud/components/EntityList.d.ts.map +1 -1
- package/dist/crud/components/EntityList.js +40 -24
- package/dist/crud/components/EntityRecommendations.d.ts +1 -1
- package/dist/crud/components/EntityRecommendations.d.ts.map +1 -1
- package/dist/crud/components/EntityRecommendations.js +4 -4
- package/dist/crud/crudImports.d.ts +1 -0
- package/dist/crud/crudImports.d.ts.map +1 -1
- package/dist/crud/crudImports.js +1 -0
- package/dist/dndev-next.css +198 -75
- package/dist/dndev.css +228 -74
- package/dist/index.js +4 -4
- package/dist/internal/common/ErrorFallback.js +1 -1
- package/dist/internal/devtools/DebugTools.js +1 -1
- package/dist/internal/devtools/components/DesignTab.d.ts.map +1 -1
- package/dist/internal/devtools/components/DesignTab.js +6 -2
- package/dist/internal/devtools/utils/envVarDiscovery.d.ts.map +1 -1
- package/dist/internal/devtools/utils/envVarDiscovery.js +4 -5
- package/dist/internal/devtools/utils/virtualModuleInspector.d.ts.map +1 -1
- package/dist/internal/devtools/utils/virtualModuleInspector.js +2 -0
- package/dist/internal/initializers/BaseStoresInitializer.d.ts.map +1 -1
- package/dist/internal/initializers/BaseStoresInitializer.js +11 -2
- package/dist/internal/layout/DnDevLayout.d.ts.map +1 -1
- package/dist/internal/layout/DnDevLayout.js +39 -16
- package/dist/internal/layout/components/AutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/AutoMetaTags.js +55 -23
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts +2 -0
- package/dist/internal/layout/components/NextJsAutoMetaTags.d.ts.map +1 -1
- package/dist/internal/layout/components/NextJsAutoMetaTags.js +45 -15
- package/dist/internal/layout/components/PWAUpdateNotification.d.ts.map +1 -1
- package/dist/internal/layout/components/PWAUpdateNotification.js +15 -2
- package/dist/internal/layout/zones/DnDevFooter.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevFooter.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevFooter.js +5 -1
- package/dist/internal/layout/zones/DnDevHeader.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevHeader.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevHeader.js +7 -2
- package/dist/internal/layout/zones/DnDevSidebar.d.ts +3 -1
- package/dist/internal/layout/zones/DnDevSidebar.d.ts.map +1 -1
- package/dist/internal/layout/zones/DnDevSidebar.js +9 -3
- package/dist/providers/NextJsAppProviders.d.ts.map +1 -1
- package/dist/providers/NextJsAppProviders.js +3 -1
- package/dist/routing/AuthGuard.d.ts +7 -22
- package/dist/routing/AuthGuard.d.ts.map +1 -1
- package/dist/routing/AuthGuard.js +19 -64
- package/dist/routing/AuthReturnTo.d.ts +13 -0
- package/dist/routing/AuthReturnTo.d.ts.map +1 -0
- package/dist/routing/AuthReturnTo.js +61 -0
- package/dist/routing/DnDevNavigationMenu.d.ts +1 -0
- package/dist/routing/DnDevNavigationMenu.d.ts.map +1 -1
- package/dist/routing/GoTo.d.ts +1 -0
- package/dist/routing/GoTo.d.ts.map +1 -1
- package/dist/routing/hooks/hooks.next.js +1 -1
- package/dist/routing/hooks/hooks.vite.js +1 -1
- package/dist/routing/hooks/useNavigate.next.d.ts +8 -0
- package/dist/routing/hooks/useNavigate.next.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.next.js +58 -8
- package/dist/routing/hooks/useNavigate.vite.d.ts +8 -0
- package/dist/routing/hooks/useNavigate.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useNavigate.vite.js +64 -14
- package/dist/routing/hooks/useRedirectGuard.next.d.ts +2 -0
- package/dist/routing/hooks/useRedirectGuard.next.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.next.js +11 -27
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts +2 -0
- package/dist/routing/hooks/useRedirectGuard.vite.d.ts.map +1 -1
- package/dist/routing/hooks/useRedirectGuard.vite.js +11 -27
- package/dist/routing/index.d.ts +1 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -0
- package/dist/styles/index.css +228 -74
- package/dist/symbol-index.json +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/sanitizeSvg.d.ts +4 -0
- package/dist/utils/sanitizeSvg.d.ts.map +1 -1
- package/dist/utils/sanitizeSvg.js +4 -0
- package/dist/utils/useAISafe.d.ts +28 -0
- package/dist/utils/useAISafe.d.ts.map +1 -0
- package/dist/utils/useAISafe.js +53 -0
- package/dist/utils/useAuthSafe.d.ts +39 -0
- package/dist/utils/useAuthSafe.d.ts.map +1 -1
- package/dist/utils/useAuthSafe.js +5 -0
- package/dist/utils/useAuthVisibility.d.ts +1 -0
- package/dist/utils/useAuthVisibility.d.ts.map +1 -1
- package/dist/utils/useBillingVisibility.d.ts +1 -0
- package/dist/utils/useBillingVisibility.d.ts.map +1 -1
- package/dist/utils/useSeo.d.ts +121 -0
- package/dist/utils/useSeo.d.ts.map +1 -0
- package/dist/utils/useSeo.js +114 -0
- package/dist/vite-routing/AppRoutes.d.ts.map +1 -1
- package/dist/vite-routing/AppRoutes.js +14 -4
- package/dist/vite-routing/RootLayout.d.ts.map +1 -1
- package/dist/vite-routing/RootLayout.js +6 -4
- package/guidelines/COMPONENTS.md +136 -0
- package/guidelines/GOTCHAS.md +66 -0
- package/guidelines/LAYOUTS.md +310 -0
- package/guidelines/PAGES.md +205 -0
- package/guidelines/ROUTING.md +499 -0
- package/guidelines/SEO.md +275 -0
- package/package.json +12 -7
- package/dist/chunk-XHGRMKOY.js +0 -1
|
@@ -2,23 +2,73 @@
|
|
|
2
2
|
// packages/ui/src/routing/hooks/useNavigate.next.ts
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Next.js-specific navigation hooks
|
|
5
|
-
* @description Navigation hooks for Next.js App Router
|
|
5
|
+
* @description Navigation hooks for Next.js App Router with auth interception
|
|
6
6
|
*
|
|
7
7
|
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
11
|
import { useRouter as useNextRouter } from 'next/navigation';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { isClient, useOverlayStore, useAuthConfig, FEATURE_STATUS, getRoutes, safeSessionStorage, } from '@donotdev/core';
|
|
13
|
+
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
14
|
+
/**
|
|
15
|
+
* Check if a route requires auth by reading discovered routes.
|
|
16
|
+
*
|
|
17
|
+
* Uses exact path match + startsWith for nested routes. Does NOT handle
|
|
18
|
+
* parameterized routes (e.g. `/blog/:slug`). Current protected routes are
|
|
19
|
+
* all exact paths. If parameterized auth routes are added, this needs
|
|
20
|
+
* pattern matching (pathToRegexp or similar).
|
|
21
|
+
*
|
|
22
|
+
* @grill-refuted getRoutes() timing is safe - virtual module hydrates synchronously
|
|
23
|
+
* before React renders. If routes aren't loaded, returns false (fail-open).
|
|
24
|
+
* Cold load is covered by AuthGuard as belt-and-suspenders.
|
|
25
|
+
*/
|
|
26
|
+
function routeRequiresAuth(path) {
|
|
27
|
+
try {
|
|
28
|
+
const routes = getRoutes();
|
|
29
|
+
if (!routes?.length)
|
|
30
|
+
return false;
|
|
31
|
+
const route = routes.find((r) => r.path === path || path.startsWith(r.path + '/'));
|
|
32
|
+
if (!route)
|
|
33
|
+
return false;
|
|
34
|
+
if (route.auth === true)
|
|
35
|
+
return true;
|
|
36
|
+
if (typeof route.auth === 'object' && route.auth?.required)
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Navigation hook with auth interception.
|
|
46
|
+
*
|
|
47
|
+
* @grill-refuted Returns a new function ref each render (no useCallback). Safe because
|
|
48
|
+
* AuthGuard's useEffect that depends on navigate is guarded by `shouldRedirect && redirectTo` -
|
|
49
|
+
* the effect body is a no-op when not redirecting, and after redirect the component unmounts.
|
|
50
|
+
* React 19 - no useCallback unless profiler proves bottleneck.
|
|
51
|
+
*/
|
|
14
52
|
export function useNavigate() {
|
|
15
53
|
const router = useNextRouter();
|
|
16
54
|
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
17
|
-
|
|
55
|
+
const user = useAuthSafe('user');
|
|
56
|
+
const status = useAuthSafe('status');
|
|
57
|
+
const authConfig = useAuthConfig();
|
|
58
|
+
return (to, options) => {
|
|
18
59
|
if (to === 'back') {
|
|
19
60
|
closeAll();
|
|
20
61
|
return router.back();
|
|
21
62
|
}
|
|
63
|
+
// Auth interception: block SPA nav to protected routes when not auth'd.
|
|
64
|
+
// Skip while INITIALIZING - user may be authenticated but not resolved yet.
|
|
65
|
+
if (!user && status !== FEATURE_STATUS.INITIALIZING && routeRequiresAuth(to)) {
|
|
66
|
+
safeSessionStorage.setItem('dndev.auth.returnTo', to);
|
|
67
|
+
safeSessionStorage.setItem('dndev.auth.guardToast', '1');
|
|
68
|
+
closeAll();
|
|
69
|
+
/** @grill-refuted authRoute! safe - useAuthConfig() guarantees DEFAULT_AUTH merge provides '/' */
|
|
70
|
+
return router.replace(authConfig.authRoute);
|
|
71
|
+
}
|
|
22
72
|
closeAll();
|
|
23
73
|
if (options?.preserveScroll && isClient()) {
|
|
24
74
|
const scrollY = window.scrollY;
|
|
@@ -36,17 +86,17 @@ export function useNavigate() {
|
|
|
36
86
|
if (options?.replace)
|
|
37
87
|
return router.replace(to);
|
|
38
88
|
return router.push(to);
|
|
39
|
-
}
|
|
89
|
+
};
|
|
40
90
|
}
|
|
41
91
|
export function useBack() {
|
|
42
92
|
const router = useNextRouter();
|
|
43
|
-
return
|
|
93
|
+
return () => router.back();
|
|
44
94
|
}
|
|
45
95
|
export function useRefresh() {
|
|
46
96
|
const router = useNextRouter();
|
|
47
|
-
return
|
|
97
|
+
return () => router.refresh();
|
|
48
98
|
}
|
|
49
99
|
export function usePrefetch() {
|
|
50
100
|
const router = useNextRouter();
|
|
51
|
-
return
|
|
101
|
+
return (to) => router.prefetch(to);
|
|
52
102
|
}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import type { NavigateOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Navigation hook with auth interception.
|
|
4
|
+
*
|
|
5
|
+
* @grill-refuted Returns a new function ref each render (no useCallback). Safe because
|
|
6
|
+
* AuthGuard's useEffect that depends on navigate is guarded by `shouldRedirect && redirectTo` -
|
|
7
|
+
* the effect body is a no-op when not redirecting, and after redirect the component unmounts.
|
|
8
|
+
* React 19 - no useCallback unless profiler proves bottleneck.
|
|
9
|
+
*/
|
|
2
10
|
export declare function useNavigate(): (to: string, options?: NavigateOptions) => void | Promise<void>;
|
|
3
11
|
export declare function useBack(): () => void | Promise<void>;
|
|
4
12
|
export declare function useRefresh(): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNavigate.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useNavigate.vite.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA8B/C;;;;;;;GAOG;AACH,wBAAgB,WAAW,KAOjB,IAAI,MAAM,EAAE,UAAU,eAAe,0BAqB9C;AAED,wBAAgB,OAAO,+BAGtB;AAED,wBAAgB,UAAU,eAIzB;AAED,wBAAgB,WAAW,KACjB,KAAK,MAAM,UAGpB"}
|
|
@@ -2,41 +2,91 @@
|
|
|
2
2
|
// packages/ui/src/routing/hooks/useNavigate.vite.ts
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview Vite-specific navigation hooks
|
|
5
|
-
* @description Navigation hooks for React Router (Vite)
|
|
5
|
+
* @description Navigation hooks for React Router (Vite) with auth interception
|
|
6
6
|
*
|
|
7
7
|
* @version 0.1.0
|
|
8
8
|
* @since 0.0.1
|
|
9
9
|
* @author AMBROISE PARK Consulting
|
|
10
10
|
*/
|
|
11
|
-
import { useCallback } from 'react';
|
|
12
11
|
import { useNavigate as useRouterNavigate } from 'react-router-dom';
|
|
13
|
-
import { isClient, useOverlayStore } from '@donotdev/core';
|
|
12
|
+
import { isClient, useOverlayStore, useAuthConfig, FEATURE_STATUS, getRoutes, safeSessionStorage, } from '@donotdev/core';
|
|
13
|
+
import { useAuthSafe } from '../../utils/useAuthSafe';
|
|
14
|
+
/**
|
|
15
|
+
* Check if a route requires auth by reading discovered routes.
|
|
16
|
+
*
|
|
17
|
+
* Uses exact path match + startsWith for nested routes. Does NOT handle
|
|
18
|
+
* parameterized routes (e.g. `/blog/:slug`). Current protected routes are
|
|
19
|
+
* all exact paths. If parameterized auth routes are added, this needs
|
|
20
|
+
* pattern matching (pathToRegexp or similar).
|
|
21
|
+
*
|
|
22
|
+
* @grill-refuted getRoutes() timing is safe - virtual module hydrates synchronously
|
|
23
|
+
* before React renders. If routes aren't loaded, returns false (fail-open).
|
|
24
|
+
* Cold load is covered by AuthGuard as belt-and-suspenders.
|
|
25
|
+
*/
|
|
26
|
+
function routeRequiresAuth(path) {
|
|
27
|
+
try {
|
|
28
|
+
const routes = getRoutes();
|
|
29
|
+
if (!routes?.length)
|
|
30
|
+
return false;
|
|
31
|
+
const route = routes.find((r) => r.path === path || path.startsWith(r.path + '/'));
|
|
32
|
+
if (!route)
|
|
33
|
+
return false;
|
|
34
|
+
if (route.auth === true)
|
|
35
|
+
return true;
|
|
36
|
+
if (typeof route.auth === 'object' && route.auth?.required)
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Navigation hook with auth interception.
|
|
46
|
+
*
|
|
47
|
+
* @grill-refuted Returns a new function ref each render (no useCallback). Safe because
|
|
48
|
+
* AuthGuard's useEffect that depends on navigate is guarded by `shouldRedirect && redirectTo` -
|
|
49
|
+
* the effect body is a no-op when not redirecting, and after redirect the component unmounts.
|
|
50
|
+
* React 19 - no useCallback unless profiler proves bottleneck.
|
|
51
|
+
*/
|
|
14
52
|
export function useNavigate() {
|
|
15
|
-
const
|
|
53
|
+
const routerNavigate = useRouterNavigate();
|
|
16
54
|
const closeAll = useOverlayStore((state) => state.closeAll);
|
|
17
|
-
|
|
55
|
+
const user = useAuthSafe('user');
|
|
56
|
+
const status = useAuthSafe('status');
|
|
57
|
+
const authConfig = useAuthConfig();
|
|
58
|
+
return (to, options) => {
|
|
18
59
|
if (to === 'back') {
|
|
19
60
|
closeAll();
|
|
20
|
-
return
|
|
61
|
+
return routerNavigate(-1);
|
|
62
|
+
}
|
|
63
|
+
// Auth interception: block SPA nav to protected routes when not auth'd.
|
|
64
|
+
// Skip while INITIALIZING - user may be authenticated but not resolved yet.
|
|
65
|
+
if (!user && status !== FEATURE_STATUS.INITIALIZING && routeRequiresAuth(to)) {
|
|
66
|
+
safeSessionStorage.setItem('dndev.auth.returnTo', to);
|
|
67
|
+
safeSessionStorage.setItem('dndev.auth.guardToast', '1');
|
|
68
|
+
closeAll();
|
|
69
|
+
/** @grill-refuted authRoute! safe - useAuthConfig() guarantees DEFAULT_AUTH merge provides '/' */
|
|
70
|
+
return routerNavigate(authConfig.authRoute, { replace: true });
|
|
21
71
|
}
|
|
22
72
|
closeAll();
|
|
23
73
|
if (options?.replace)
|
|
24
|
-
return
|
|
25
|
-
return
|
|
26
|
-
}
|
|
74
|
+
return routerNavigate(to, { replace: true });
|
|
75
|
+
return routerNavigate(to);
|
|
76
|
+
};
|
|
27
77
|
}
|
|
28
78
|
export function useBack() {
|
|
29
79
|
const navigate = useRouterNavigate();
|
|
30
|
-
return
|
|
80
|
+
return () => navigate(-1);
|
|
31
81
|
}
|
|
32
82
|
export function useRefresh() {
|
|
33
|
-
return
|
|
83
|
+
return () => {
|
|
34
84
|
if (isClient())
|
|
35
85
|
window.location.reload();
|
|
36
|
-
}
|
|
86
|
+
};
|
|
37
87
|
}
|
|
38
88
|
export function usePrefetch() {
|
|
39
|
-
return
|
|
89
|
+
return (_to) => {
|
|
40
90
|
// Vite: no-op
|
|
41
|
-
}
|
|
91
|
+
};
|
|
42
92
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageAuth, FeatureStatus } from '@donotdev/core';
|
|
2
|
+
/** Configuration options for the redirect guard hook. */
|
|
2
3
|
export interface RedirectGuardOptions {
|
|
3
4
|
/** Auth configuration for this route */
|
|
4
5
|
auth?: PageAuth | false;
|
|
@@ -7,6 +8,7 @@ export interface RedirectGuardOptions {
|
|
|
7
8
|
/** Custom condition function to check if redirect should happen */
|
|
8
9
|
condition?: (user: any, status: FeatureStatus) => boolean;
|
|
9
10
|
}
|
|
11
|
+
/** Return value of the useRedirectGuard hook. */
|
|
10
12
|
export interface RedirectGuardResult {
|
|
11
13
|
/** Whether redirect should happen */
|
|
12
14
|
shouldRedirect: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useRedirectGuard.next.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.next.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA4FrB"}
|
|
@@ -32,21 +32,13 @@ export function useRedirectGuard(options = {}) {
|
|
|
32
32
|
const status = useAuthSafe('status');
|
|
33
33
|
// Determine redirect state
|
|
34
34
|
const redirectState = useMemo(() => {
|
|
35
|
+
const noAction = { shouldRedirect: false, redirectTo: null, isChecking: false };
|
|
35
36
|
// SSR-safe: return safe defaults on server
|
|
36
|
-
if (!isClient())
|
|
37
|
-
return
|
|
38
|
-
shouldRedirect: false,
|
|
39
|
-
redirectTo: null,
|
|
40
|
-
isChecking: false,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
37
|
+
if (!isClient())
|
|
38
|
+
return noAction;
|
|
43
39
|
// Only INITIALIZING = still checking. DEGRADED/ERROR/READY = auth resolved (proceed with current user)
|
|
44
40
|
if (status === FEATURE_STATUS.INITIALIZING) {
|
|
45
|
-
return {
|
|
46
|
-
shouldRedirect: false,
|
|
47
|
-
redirectTo: null,
|
|
48
|
-
isChecking: true,
|
|
49
|
-
};
|
|
41
|
+
return { ...noAction, isChecking: true };
|
|
50
42
|
}
|
|
51
43
|
// Custom condition provided
|
|
52
44
|
if (condition) {
|
|
@@ -59,27 +51,23 @@ export function useRedirectGuard(options = {}) {
|
|
|
59
51
|
}
|
|
60
52
|
// Use auth config to determine redirect
|
|
61
53
|
if (auth !== false && auth !== undefined) {
|
|
62
|
-
if (!can)
|
|
63
|
-
return
|
|
64
|
-
shouldRedirect: false,
|
|
65
|
-
redirectTo: null,
|
|
66
|
-
isChecking: false,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
54
|
+
if (!can)
|
|
55
|
+
return noAction;
|
|
69
56
|
// Check if user can navigate to this route
|
|
70
57
|
if (!can.navigate(auth)) {
|
|
71
58
|
let targetRoute = null;
|
|
72
|
-
// Authentication failure (not logged in)
|
|
59
|
+
// Authentication failure (not logged in) → always redirect
|
|
73
60
|
if (typeof auth === 'object' && auth.required && !user) {
|
|
74
61
|
// Check if we have OAuth parameters that need to be preserved
|
|
75
62
|
const hasOAuthParams = location.search?.includes('code=') ||
|
|
76
63
|
location.search?.includes('state=') ||
|
|
77
64
|
location.search?.includes('error=');
|
|
65
|
+
const authRoute = authConfig.authRoute;
|
|
78
66
|
if (hasOAuthParams) {
|
|
79
|
-
targetRoute = `${
|
|
67
|
+
targetRoute = `${authRoute}${location.search}`;
|
|
80
68
|
}
|
|
81
69
|
else {
|
|
82
|
-
targetRoute =
|
|
70
|
+
targetRoute = authRoute;
|
|
83
71
|
}
|
|
84
72
|
}
|
|
85
73
|
// Authorization failure (wrong role)
|
|
@@ -102,11 +90,7 @@ export function useRedirectGuard(options = {}) {
|
|
|
102
90
|
}
|
|
103
91
|
}
|
|
104
92
|
// No redirect needed
|
|
105
|
-
return
|
|
106
|
-
shouldRedirect: false,
|
|
107
|
-
redirectTo: null,
|
|
108
|
-
isChecking: false,
|
|
109
|
-
};
|
|
93
|
+
return noAction;
|
|
110
94
|
}, [
|
|
111
95
|
auth,
|
|
112
96
|
status,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PageAuth, FeatureStatus } from '@donotdev/core';
|
|
2
|
+
/** Configuration options for the redirect guard hook. */
|
|
2
3
|
export interface RedirectGuardOptions {
|
|
3
4
|
/** Auth configuration for this route */
|
|
4
5
|
auth?: PageAuth | false;
|
|
@@ -7,6 +8,7 @@ export interface RedirectGuardOptions {
|
|
|
7
8
|
/** Custom condition function to check if redirect should happen */
|
|
8
9
|
condition?: (user: any, status: FeatureStatus) => boolean;
|
|
9
10
|
}
|
|
11
|
+
/** Return value of the useRedirectGuard hook. */
|
|
10
12
|
export interface RedirectGuardResult {
|
|
11
13
|
/** Whether redirect should happen */
|
|
12
14
|
shouldRedirect: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useRedirectGuard.vite.d.ts","sourceRoot":"","sources":["../../../src/routing/hooks/useRedirectGuard.vite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK9D,yDAAyD;AACzD,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IACxB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,mEAAmE;IACnE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC;CAC3D;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,qCAAqC;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,uDAAuD;IACvD,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CA4FrB"}
|
|
@@ -32,21 +32,13 @@ export function useRedirectGuard(options = {}) {
|
|
|
32
32
|
const status = useAuthSafe('status');
|
|
33
33
|
// Determine redirect state
|
|
34
34
|
const redirectState = useMemo(() => {
|
|
35
|
+
const noAction = { shouldRedirect: false, redirectTo: null, isChecking: false };
|
|
35
36
|
// SSR-safe: return safe defaults on server
|
|
36
|
-
if (!isClient())
|
|
37
|
-
return
|
|
38
|
-
shouldRedirect: false,
|
|
39
|
-
redirectTo: null,
|
|
40
|
-
isChecking: false,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
37
|
+
if (!isClient())
|
|
38
|
+
return noAction;
|
|
43
39
|
// Only INITIALIZING = still checking. DEGRADED/ERROR/READY = auth resolved (proceed with current user)
|
|
44
40
|
if (status === FEATURE_STATUS.INITIALIZING) {
|
|
45
|
-
return {
|
|
46
|
-
shouldRedirect: false,
|
|
47
|
-
redirectTo: null,
|
|
48
|
-
isChecking: true,
|
|
49
|
-
};
|
|
41
|
+
return { ...noAction, isChecking: true };
|
|
50
42
|
}
|
|
51
43
|
// Custom condition provided
|
|
52
44
|
if (condition) {
|
|
@@ -59,27 +51,23 @@ export function useRedirectGuard(options = {}) {
|
|
|
59
51
|
}
|
|
60
52
|
// Use auth config to determine redirect
|
|
61
53
|
if (auth !== false && auth !== undefined) {
|
|
62
|
-
if (!can)
|
|
63
|
-
return
|
|
64
|
-
shouldRedirect: false,
|
|
65
|
-
redirectTo: null,
|
|
66
|
-
isChecking: false,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
54
|
+
if (!can)
|
|
55
|
+
return noAction;
|
|
69
56
|
// Check if user can navigate to this route
|
|
70
57
|
if (!can.navigate(auth)) {
|
|
71
58
|
let targetRoute = null;
|
|
72
|
-
// Authentication failure (not logged in)
|
|
59
|
+
// Authentication failure (not logged in) → always redirect
|
|
73
60
|
if (typeof auth === 'object' && auth.required && !user) {
|
|
74
61
|
// Check if we have OAuth parameters that need to be preserved
|
|
75
62
|
const hasOAuthParams = location.search.includes('code=') ||
|
|
76
63
|
location.search.includes('state=') ||
|
|
77
64
|
location.search.includes('error=');
|
|
65
|
+
const authRoute = authConfig.authRoute;
|
|
78
66
|
if (hasOAuthParams) {
|
|
79
|
-
targetRoute = `${
|
|
67
|
+
targetRoute = `${authRoute}${location.search}`;
|
|
80
68
|
}
|
|
81
69
|
else {
|
|
82
|
-
targetRoute =
|
|
70
|
+
targetRoute = authRoute;
|
|
83
71
|
}
|
|
84
72
|
}
|
|
85
73
|
// Authorization failure (wrong role)
|
|
@@ -102,11 +90,7 @@ export function useRedirectGuard(options = {}) {
|
|
|
102
90
|
}
|
|
103
91
|
}
|
|
104
92
|
// No redirect needed
|
|
105
|
-
return
|
|
106
|
-
shouldRedirect: false,
|
|
107
|
-
redirectTo: null,
|
|
108
|
-
isChecking: false,
|
|
109
|
-
};
|
|
93
|
+
return noAction;
|
|
110
94
|
}, [
|
|
111
95
|
auth,
|
|
112
96
|
status,
|
package/dist/routing/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
export * from './Link';
|
|
11
11
|
export * from './AuthGuard';
|
|
12
12
|
export * from './AuthGuardFallback';
|
|
13
|
+
export { AuthReturnTo } from './AuthReturnTo';
|
|
13
14
|
export * from './GoTo';
|
|
14
15
|
export { default as GoToWrapper } from './GoToWrapper';
|
|
15
16
|
export { default as GoToInput } from './GoToInput';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAOhD,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routing/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAGH,cAAc,QAAQ,CAAC;AAGvB,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,OAAO,CAAC;AAOhD,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACT,aAAa,EACb,eAAe,EACf,QAAQ,EACR,cAAc,EACd,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
|
package/dist/routing/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from './Link';
|
|
|
14
14
|
// Public API: HeaderNavigation (path prop for single item), DnDevNavigationMenu (full menu).
|
|
15
15
|
export * from './AuthGuard';
|
|
16
16
|
export * from './AuthGuardFallback';
|
|
17
|
+
export { AuthReturnTo } from './AuthReturnTo';
|
|
17
18
|
export * from './GoTo';
|
|
18
19
|
export { default as GoToWrapper } from './GoToWrapper';
|
|
19
20
|
export { default as GoToInput } from './GoToInput';
|