Skip to content

Commit

Permalink
feat: SessionProvider 커스텀 구현 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunjun9788 committed Jan 31, 2025
1 parent b5b47a9 commit 2a80dd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ import "../styles/globals.css"
import "../styles/reset.css"
import MobileViewLayout from "../components/layout/MobileViewLayout"
import { Pretendard } from "@/fonts"
import { authOptions } from "./api/auth/[...nextauth]/auth"
import { getServerSession } from "next-auth"
import { Providers } from "./providers"

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app"
}

export default function RootLayout({
export default async function RootLayout({
children
}: Readonly<{
children: React.ReactNode
}>) {
const session = await getServerSession(authOptions)
return (
<html lang="en">
<body className={Pretendard.variable}>
<MobileViewLayout>{children}</MobileViewLayout>
<Providers session={session}>
<MobileViewLayout>{children}</MobileViewLayout>
</Providers>
</body>
</html>
)
Expand Down
15 changes: 15 additions & 0 deletions src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use client"

import { QueryClient } from "@tanstack/react-query"
import { Session } from "next-auth"
import { SessionProvider } from "next-auth/react"
import { PropsWithChildren } from "react"

interface ProvidersProps extends PropsWithChildren {
session?: Session | null
queryClient?: QueryClient
}

export const Providers = ({ session, children }: ProvidersProps) => {
return <SessionProvider session={session}>{children}</SessionProvider>
}

0 comments on commit 2a80dd5

Please sign in to comment.