@djangocfg/layouts 2.1.46 → 2.1.47

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.46",
3
+ "version": "2.1.47",
4
4
  "description": "Simple, straightforward layout components for Next.js - import and use with props",
5
5
  "keywords": [
6
6
  "layouts",
@@ -92,9 +92,9 @@
92
92
  "check": "tsc --noEmit"
93
93
  },
94
94
  "peerDependencies": {
95
- "@djangocfg/api": "^2.1.46",
96
- "@djangocfg/centrifugo": "^2.1.46",
97
- "@djangocfg/ui-nextjs": "^2.1.46",
95
+ "@djangocfg/api": "^2.1.47",
96
+ "@djangocfg/centrifugo": "^2.1.47",
97
+ "@djangocfg/ui-nextjs": "^2.1.47",
98
98
  "@hookform/resolvers": "^5.2.0",
99
99
  "consola": "^3.4.2",
100
100
  "lucide-react": "^0.545.0",
@@ -115,7 +115,7 @@
115
115
  "uuid": "^11.1.0"
116
116
  },
117
117
  "devDependencies": {
118
- "@djangocfg/typescript-config": "^2.1.46",
118
+ "@djangocfg/typescript-config": "^2.1.47",
119
119
  "@types/node": "^24.7.2",
120
120
  "@types/react": "^19.1.0",
121
121
  "@types/react-dom": "^19.1.0",
@@ -46,11 +46,12 @@
46
46
 
47
47
  'use client';
48
48
 
49
- import React, { ReactNode } from 'react';
49
+ import React, { ReactNode, useEffect, useState } from 'react';
50
+ import { useRouter } from 'next/navigation';
50
51
 
51
52
  import { useAuth } from '@djangocfg/api/auth';
52
53
  import {
53
- ButtonLink, Preloader, SidebarInset, SidebarProvider
54
+ Preloader, SidebarInset, SidebarProvider
54
55
  } from '@djangocfg/ui-nextjs/components';
55
56
 
56
57
  import { UserMenuConfig } from '../types';
@@ -93,15 +94,29 @@ export function PrivateLayout({
93
94
  header,
94
95
  contentPadding = 'default',
95
96
  }: PrivateLayoutProps) {
96
- const { isAuthenticated, isLoading } = useAuth();
97
+ const { isAuthenticated, isLoading, saveRedirectUrl } = useAuth();
98
+ const router = useRouter();
99
+ const [isRedirecting, setIsRedirecting] = useState(false);
97
100
 
98
- // Show loading state while auth is being checked
101
+ useEffect(() => {
102
+ if (!isLoading && !isAuthenticated && !isRedirecting) {
103
+ // Save current URL (including query params) before redirecting to auth
104
+ const currentUrl = window.location.pathname + window.location.search;
105
+ saveRedirectUrl(currentUrl);
106
+
107
+ // Set redirecting state to prevent flicker
108
+ setIsRedirecting(true);
109
+ router.push(header?.authPath || '/auth');
110
+ }
111
+ }, [isAuthenticated, isLoading, isRedirecting, router, saveRedirectUrl, header?.authPath]);
112
+
113
+ // Show loading state while auth is being checked or redirecting
99
114
  // Note: SSR hydration is handled by ClientOnly wrapper in AppLayout
100
- if (isLoading) {
115
+ if (isLoading || isRedirecting || !isAuthenticated) {
101
116
  return (
102
117
  <Preloader
103
118
  variant="fullscreen"
104
- text="Authenticating..."
119
+ text={isRedirecting ? "Redirecting to login..." : "Authenticating..."}
105
120
  size="lg"
106
121
  backdrop={true}
107
122
  backdropOpacity={80}
@@ -109,26 +124,6 @@ export function PrivateLayout({
109
124
  );
110
125
  }
111
126
 
112
- // Don't render if user is not authenticated
113
- if (!isAuthenticated) {
114
- return (
115
- <div className="flex flex-col items-center justify-center min-h-screen gap-4">
116
- <h3 className="text-2xl font-bold">
117
- Not Authenticated
118
- </h3>
119
- <p className="text-muted-foreground">
120
- Please log in to continue.
121
- </p>
122
- <ButtonLink
123
- variant="outline"
124
- href="/auth"
125
- >
126
- Login
127
- </ButtonLink>
128
- </div>
129
- );
130
- }
131
-
132
127
  return (
133
128
  <SidebarProvider defaultOpen={true}>
134
129
  {/* Sidebar */}