@@ -13,10 +13,8 @@ import { CookieBanner } from '@/components/shared/CookieBanner';
1313import Footer from '@/components/shared/Footer' ;
1414import { ScrollWatcher } from '@/components/shared/ScrollWatcher' ;
1515import { ThemeProvider } from '@/components/theme/ThemeProvider' ;
16+ import { AuthProvider } from '@/hooks/useAuth' ;
1617import { locales } from '@/i18n/config' ;
17- import { getCurrentUser } from '@/lib/auth' ;
18-
19- export const dynamic = 'force-dynamic' ;
2018
2119const getCachedBlogCategories = unstable_cache (
2220 async ( ) =>
@@ -41,22 +39,18 @@ export default async function LocaleLayout({
4139
4240 if ( ! locales . includes ( locale as any ) ) notFound ( ) ;
4341
44- const messages = await getMessages ( { locale } ) ;
45- const user = await getCurrentUser ( ) ;
46- const blogCategories = await getCachedBlogCategories ( ) ;
42+ const [ messages , blogCategories ] = await Promise . all ( [
43+ getMessages ( { locale } ) ,
44+ getCachedBlogCategories ( ) ,
45+ ] ) ;
4746
48- const userExists = Boolean ( user ) ;
4947 const enableAdmin =
5048 (
5149 process . env . ENABLE_ADMIN_API ??
5250 process . env . NEXT_PUBLIC_ENABLE_ADMIN ??
5351 ''
5452 ) . toLowerCase ( ) === 'true' ;
5553
56- const isAdmin = user ?. role === 'admin' ;
57- const showAdminNavLink = Boolean ( user ) && isAdmin && enableAdmin ;
58- const userId = user ?. id ?? null ;
59-
6054 return (
6155 < NextIntlClientProvider messages = { messages } >
6256 < ThemeProvider
@@ -65,20 +59,19 @@ export default async function LocaleLayout({
6559 enableSystem
6660 disableTransitionOnChange
6761 >
68- < AppChrome
69- userExists = { userExists }
70- userId = { userId }
71- showAdminLink = { showAdminNavLink }
72- blogCategories = { blogCategories }
73- >
74- < MainSwitcher
75- userExists = { userExists }
76- showAdminLink = { showAdminNavLink }
62+ < AuthProvider >
63+ < AppChrome
64+ enableAdminFeature = { enableAdmin }
7765 blogCategories = { blogCategories }
7866 >
79- { children }
80- </ MainSwitcher >
81- </ AppChrome >
67+ < MainSwitcher
68+ enableAdminFeature = { enableAdmin }
69+ blogCategories = { blogCategories }
70+ >
71+ { children }
72+ </ MainSwitcher >
73+ </ AppChrome >
74+ </ AuthProvider >
8275
8376 < Footer />
8477 < Toaster position = "top-right" richColors expand />
0 commit comments