diff --git a/app/layout.tsx b/app/layout.tsx index ced42d7b..5da2383a 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,7 +1,12 @@ +import type { Metadata } from "next"; import { Inter } from "next/font/google"; import "./globals.css"; +import { headers } from "next/headers"; +import { getServerSession } from "next-auth/next"; +import { authOptions } from "@/app/api/auth/[...nextauth]/route"; +import { LayoutWrapper } from "@/components/layout/layout-wrapper"; +import { warmupRedisCache } from '@/lib/redis'; import dynamic from 'next/dynamic'; -import { Suspense } from 'react'; // Dynamically import heavy components with proper typing const Providers = dynamic(() => import('@/components/providers'), { @@ -11,21 +16,48 @@ const Providers = dynamic(() => import('@/components/providers'), { const inter = Inter({ subsets: ["latin"] }); +// Warm up Redis connection during app initialization +warmupRedisCache().catch(console.error); + export const metadata = { title: "Neah Front", description: "Neah Front Application", }; -export default function RootLayout({ +export default async function RootLayout({ children, }: { children: React.ReactNode; }) { + // Try to get the session, but handle potential errors gracefully + let session = null; + let sessionError = false; + + try { + session = await getServerSession(authOptions); + } catch (error) { + console.error("Error getting server session:", error); + sessionError = true; + } + + const headersList = await headers(); + const pathname = headersList.get("x-pathname") || ""; + const isSignInPage = pathname === "/signin"; + + // If we're on the signin page and there was a session error, + // don't pass the session to avoid refresh attempts + const safeSession = isSignInPage && sessionError ? null : session; + return ( - + - - {children} + + + {children} +