diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index c7850b3..baf054e 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -136,7 +136,7 @@ export const authOptions: NextAuthOptions = { signIn: '/signin', error: '/signin', }, - debug: process.env.NODE_ENV === 'development', + debug: false, }; const handler = NextAuth(authOptions); diff --git a/app/layout.tsx b/app/layout.tsx index 31b8427..1da0682 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,10 +3,9 @@ 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 { authOptions } from "@/lib/auth"; import { Providers } from "@/components/providers"; import { LayoutWrapper } from "@/components/layout/layout-wrapper"; -import { SessionProvider } from "@/components/providers/session-provider"; import { Toaster } from "@/components/ui/toaster"; const inter = Inter({ subsets: ["latin"] }); @@ -16,10 +15,12 @@ export default async function RootLayout({ }: { children: React.ReactNode; }) { - const session = await getServerSession(authOptions); const headersList = headers(); const pathname = headersList.get("x-pathname") || ""; const isSignInPage = pathname === "/signin"; + + // Only check session if not on signin page + const session = !isSignInPage ? await getServerSession(authOptions) : null; return ( @@ -32,6 +33,7 @@ export default async function RootLayout({ {children} + ); diff --git a/components/auth/auth-check.tsx b/components/auth/auth-check.tsx index c8e0c21..603c397 100644 --- a/components/auth/auth-check.tsx +++ b/components/auth/auth-check.tsx @@ -2,18 +2,20 @@ import { useSession } from "next-auth/react"; import { usePathname, useRouter } from "next/navigation"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; export function AuthCheck({ children }: { children: React.ReactNode }) { const { data: session, status } = useSession(); const pathname = usePathname(); const router = useRouter(); + const [isRedirecting, setIsRedirecting] = useState(false); useEffect(() => { - if (status === "unauthenticated" && pathname !== "/signin") { + if (status === "unauthenticated" && pathname !== "/signin" && !isRedirecting) { + setIsRedirecting(true); router.push("/signin"); } - }, [status, router, pathname]); + }, [status, router, pathname, isRedirecting]); if (status === "loading") { return
Chargement...
;