From 12a73e2fed5c6a08fd039a6ff4988a3f3273fb78 Mon Sep 17 00:00:00 2001 From: abdout Date: Sat, 25 Apr 2026 11:36:46 +0300 Subject: [PATCH] fix(auth): restore SessionProvider in [lang]/layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without SessionProvider, every client useSession() returned unauthenticated regardless of server-side state — breaking useCurrentUser, useCurrentRole, RoleGate, user-button avatar, pricing role/delete forms. Restores the wrapper at the layout level. The server layout calls auth() once in parallel with params resolution (Promise.all), and passes the session to SessionProvider for client descendants. The pages: { signIn, error } config in src/auth.ts is left as-is — proxy.ts already prefixes the user's locale on the next request after the redirect, so /login lands on /{locale}/login by cookie. Closes #9 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/app/[lang]/layout.tsx | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/app/[lang]/layout.tsx b/src/app/[lang]/layout.tsx index 7885e5f..c1f3021 100644 --- a/src/app/[lang]/layout.tsx +++ b/src/app/[lang]/layout.tsx @@ -9,8 +9,8 @@ import { ImageKitProvider } from "@/components/ui/imagekit-provider"; import { Toaster } from "sonner"; import { getDictionary } from "@/components/internationalization/dictionaries"; import { type Locale, localeConfig } from "@/components/internationalization/config"; -// import { SessionProvider } from "next-auth/react"; -// import { auth } from "@/auth"; +import { SessionProvider } from "next-auth/react"; +import { auth } from "@/auth"; // Configure Rubik font for Arabic const rubik = Rubik({ @@ -80,11 +80,10 @@ export default async function LocaleLayout({ children: React.ReactNode; params: Promise<{ lang: Locale }>; }>) { - // const session = await auth(); - const { lang } = await params; + const [{ lang }, session] = await Promise.all([params, auth()]); const config = localeConfig[lang]; const isRTL = config.dir === 'rtl'; - + return ( - {/* */} - - - -
- - - {children} -
-
-
- - {/*
*/} + + + +
+ + {children} +
+
+
+
);