|
1 | 1 | import { NextIntlClientProvider } from "next-intl"; |
2 | 2 | import { getMessages, getTranslations, setRequestLocale } from "next-intl/server"; |
3 | 3 | import { Sora } from "next/font/google"; |
4 | | -import WrapperLayout from "@/components/layout/WrapperLayout"; |
5 | 4 | import { locales } from "@/lib/locales"; |
6 | 5 | import { notFound } from "next/navigation"; |
7 | 6 | import { Toaster } from "@/components/ui/Toaster"; |
| 7 | +import { AuthProvider } from "@/components/provider/AuthProvider"; |
| 8 | +import { cookies } from "next/headers"; |
| 9 | +import { AuthJwtPayload } from "@/types"; |
| 10 | +import { jwtDecode } from "jwt-decode"; |
| 11 | +import { ThemeProvider } from "@/components/provider/ThemeProvider"; |
8 | 12 | const sora = Sora({ subsets: ["latin"] }); |
9 | 13 |
|
10 | 14 | type Props = { |
@@ -33,22 +37,31 @@ export async function generateMetadata(props: Props) { |
33 | 37 |
|
34 | 38 | export default async function LocaleRootLayout(props: Readonly<Props>) { |
35 | 39 | const params = await props.params; |
36 | | - |
37 | 40 | const { locale } = params; |
38 | | - |
39 | 41 | const { children } = props; |
40 | 42 |
|
41 | 43 | if (!locales.includes(locale)) notFound(); |
42 | 44 |
|
43 | 45 | setRequestLocale(locale); |
44 | 46 |
|
| 47 | + // Get authenticated user info |
| 48 | + // This data is retrieved on server context |
| 49 | + // Then we passed it into auth provider |
| 50 | + const cookieStore = await cookies(); |
| 51 | + const token = cookieStore.get("token"); |
| 52 | + const payload: AuthJwtPayload | undefined = token?.value ? jwtDecode<AuthJwtPayload>(token.value) : undefined; |
| 53 | + |
45 | 54 | const messages = await getMessages(); |
46 | 55 |
|
47 | 56 | return ( |
48 | 57 | <html lang={locale} suppressHydrationWarning> |
49 | 58 | <body className={`${sora.className}`}> |
50 | 59 | <NextIntlClientProvider messages={messages}> |
51 | | - <WrapperLayout>{children}</WrapperLayout> |
| 60 | + <AuthProvider payload={payload}> |
| 61 | + <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange> |
| 62 | + {children} |
| 63 | + </ThemeProvider> |
| 64 | + </AuthProvider> |
52 | 65 | <Toaster /> |
53 | 66 | </NextIntlClientProvider> |
54 | 67 | </body> |
|
0 commit comments