@djangocfg/layouts 2.1.619 → 2.1.621

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/layouts",
3
- "version": "2.1.619",
3
+ "version": "2.1.621",
4
4
  "description": "Simple, straightforward layout components for Next.js - import and use with props",
5
5
  "keywords": [
6
6
  "layouts",
@@ -91,11 +91,11 @@
91
91
  "test": "vitest run"
92
92
  },
93
93
  "peerDependencies": {
94
- "@djangocfg/analytics": "^2.1.619",
95
- "@djangocfg/api": "^2.1.619",
96
- "@djangocfg/devtools": "^2.1.619",
97
- "@djangocfg/i18n": "^2.1.619",
98
- "@djangocfg/ui-core": "^2.1.619",
94
+ "@djangocfg/analytics": "^2.1.621",
95
+ "@djangocfg/api": "^2.1.621",
96
+ "@djangocfg/devtools": "^2.1.621",
97
+ "@djangocfg/i18n": "^2.1.621",
98
+ "@djangocfg/ui-core": "^2.1.621",
99
99
  "@hookform/resolvers": "^5.2.2 || ^7.0.2",
100
100
  "consola": "^3.4.2",
101
101
  "lucide-react": "^1.68.0",
@@ -123,12 +123,12 @@
123
123
  "qrcode.react": "^4.2.0"
124
124
  },
125
125
  "devDependencies": {
126
- "@djangocfg/analytics": "^2.1.619",
127
- "@djangocfg/api": "^2.1.619",
128
- "@djangocfg/devtools": "^2.1.619",
129
- "@djangocfg/i18n": "^2.1.619",
130
- "@djangocfg/typescript-config": "^2.1.619",
131
- "@djangocfg/ui-core": "^2.1.619",
126
+ "@djangocfg/analytics": "^2.1.621",
127
+ "@djangocfg/api": "^2.1.621",
128
+ "@djangocfg/devtools": "^2.1.621",
129
+ "@djangocfg/i18n": "^2.1.621",
130
+ "@djangocfg/typescript-config": "^2.1.621",
131
+ "@djangocfg/ui-core": "^2.1.621",
132
132
  "@storybook/react-vite": "^10.6.5",
133
133
  "@types/node": "^25.9.5",
134
134
  "@types/react": "19.3.0",
@@ -102,12 +102,14 @@ export function PrivateLayout({
102
102
 
103
103
  if (isLoading) {
104
104
  return (
105
+ // The auth gate covers the whole viewport: solid, above the chat dock (z-100), sheets, dialogs and popovers.
106
+ // Nothing behind it may show or take a click while the session is still being decided.
105
107
  <Preloader
106
108
  variant="fullscreen"
107
109
  text={loadingText}
108
110
  size="lg"
109
- backdrop={true}
110
- backdropOpacity={80}
111
+ backdrop={false}
112
+ className="z-[9996] bg-background"
111
113
  />
112
114
  );
113
115
  }
@@ -9,13 +9,13 @@
9
9
  import { useEffect, useState } from 'react';
10
10
  import { useRouter } from 'next/navigation';
11
11
 
12
- import { auth } from '@djangocfg/api';
13
12
  import {
14
13
  useAuth,
15
14
  resolveGuardIsLoading,
16
15
  resolveGuardIsAuthenticated,
17
16
  shouldRedirectToAuth,
18
17
  isForbidden,
18
+ authTrace,
19
19
  } from '@djangocfg/api/auth';
20
20
 
21
21
  interface UseAuthGuardOptions {
@@ -28,10 +28,8 @@ interface UseAuthGuardOptions {
28
28
  /** Explicit override; defaults to the app's resolved `useAuth().routes.auth`. */
29
29
  authPath?: string;
30
30
  /**
31
- * Safety net: if auth is still "loading" this many ms after mount, stop
32
- * waiting and let the guard decide from whatever token state we have. Prevents
33
- * an endless preloader if AuthContext initialization ever wedges (a hung
34
- * request, a CSP-swallowed response, an unresolved promise). Default 8s.
31
+ * @deprecated No effect. The provider owns the single safety timer (8 s), so
32
+ * `status` always leaves 'resolving'. Kept so existing callers still compile.
35
33
  */
36
34
  loadingTimeoutMs?: number;
37
35
  }
@@ -51,9 +49,11 @@ export function useAuthGuard({
51
49
  requireAuth = true,
52
50
  requireStaff = false,
53
51
  authPath,
54
- loadingTimeoutMs = 8000,
55
52
  }: UseAuthGuardOptions): UseAuthGuardResult {
56
- const { isAuthenticated, isLoading: authLoading, isAdminUser, saveRedirectUrl, routes } = useAuth();
53
+ const { status, isAdminUser, saveRedirectUrl, routes } = useAuth();
54
+ // One linear state decides everything: 'resolving' → spinner, 'authenticated' → render, 'anonymous' → redirect.
55
+ const isAuthenticated = status === 'authenticated';
56
+ const authLoading = status === 'resolving';
57
57
  const resolvedAuthPath = authPath ?? routes.auth;
58
58
  const router = useRouter();
59
59
  const [isRedirecting, setIsRedirecting] = useState(false);
@@ -66,26 +66,14 @@ export function useAuthGuard({
66
66
  const [mounted, setMounted] = useState(false);
67
67
  useEffect(() => setMounted(true), []);
68
68
 
69
- // Safety-net timeout: force auth to be considered "resolved" if it hasn't
70
- // settled within loadingTimeoutMs, so the guard can act (render or redirect)
71
- // instead of spinning forever. Only armed while actually loading.
72
- const [authTimedOut, setAuthTimedOut] = useState(false);
73
- useEffect(() => {
74
- if (!mounted || !authLoading || authTimedOut) return;
75
- const t = setTimeout(() => setAuthTimedOut(true), loadingTimeoutMs);
76
- return () => clearTimeout(t);
77
- }, [mounted, authLoading, authTimedOut, loadingTimeoutMs]);
78
-
79
69
  // Guard state derives from a single pure resolver (see @djangocfg/api/auth
80
70
  // utils/guard) so the "spinner vs redirect vs render" decision is unit-tested
81
71
  // in isolation and can't silently regress into the "stuck on Authenticating…"
82
72
  // state where a resolved-but-unauthenticated session never redirects.
83
- // `authLoading` is forced false once the safety-net timeout fires.
84
- const effectiveAuthLoading = authLoading && !authTimedOut;
85
73
  const guardState = {
86
74
  mounted,
87
75
  requireAuth,
88
- authLoading: effectiveAuthLoading,
76
+ authLoading,
89
77
  isRedirecting,
90
78
  isAuthenticated,
91
79
  requireStaff,
@@ -93,16 +81,15 @@ export function useAuthGuard({
93
81
  };
94
82
 
95
83
  useEffect(() => {
96
- // The React snapshot can still be the server's 'anonymous' while the store holds a live session (hydration, or a
97
- // full-page load right after sign-in). Never redirect on that: the snapshot catches up and the effect re-runs.
98
- if (shouldRedirectToAuth(guardState) && !auth.isAuthenticated()) {
84
+ if (shouldRedirectToAuth(guardState)) {
99
85
  const currentUrl = window.location.pathname + window.location.search;
86
+ authTrace('guard.redirect', { from: window.location.pathname, to: resolvedAuthPath });
100
87
  saveRedirectUrl(currentUrl);
101
88
  setIsRedirecting(true);
102
89
  router.push(resolvedAuthPath);
103
90
  }
104
91
  // eslint-disable-next-line react-hooks/exhaustive-deps
105
- }, [mounted, requireAuth, isAuthenticated, effectiveAuthLoading, isRedirecting, router, saveRedirectUrl, resolvedAuthPath]);
92
+ }, [mounted, requireAuth, isAuthenticated, authLoading, isRedirecting, router, saveRedirectUrl, resolvedAuthPath]);
106
93
 
107
94
  const isLoading = resolveGuardIsLoading(guardState);
108
95
  const loadingText = isRedirecting ? 'Redirecting to login...' : 'Authenticating...';
@@ -63,6 +63,7 @@ export const MockAuthProvider: React.FC<MockAuthProviderProps> = ({
63
63
  const value = useMemo<AuthContextType>(() => ({
64
64
  user,
65
65
  isLoading,
66
+ status: isLoading ? 'resolving' : (isAuthenticated ?? Boolean(user)) ? 'authenticated' : 'anonymous',
66
67
  isAuthenticated: isAuthenticated ?? Boolean(user),
67
68
  isAdminUser,
68
69
  routes: { auth: '/auth', defaultCallback: '/', defaultAuthCallback: '/auth', ...routes },