55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
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 { Providers } from "@/components/providers";
|
|
import { LayoutWrapper } from "@/components/layout/layout-wrapper";
|
|
import { warmupRedisCache } from '@/lib/redis';
|
|
|
|
const inter = Inter({ subsets: ["latin"] });
|
|
|
|
// Warm up Redis connection during app initialization
|
|
warmupRedisCache().catch(console.error);
|
|
|
|
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 (
|
|
<html lang="fr">
|
|
<body className={inter.className}>
|
|
<Providers session={safeSession}>
|
|
<LayoutWrapper
|
|
isSignInPage={isSignInPage}
|
|
isAuthenticated={!!session && !sessionError}
|
|
>
|
|
{children}
|
|
</LayoutWrapper>
|
|
</Providers>
|
|
</body>
|
|
</html>
|
|
);
|
|
}
|