I have a Next app. I use app folder and Next Auth library. So that each page has access to the session, I wrapped the entire application in a SessionProvider
. But since it's useContext
under the hood, I had to add the 'use client'
directive everywhere. This resulted in all pages being client-side since they use useSession
. And all page components (buttons, inputs) also became client-side.
app/layout.tsx
const RootLayout = ({ session, children }: { session: Session; children: ReactNode }) => {
return (
<SessionProvider session={session}>
<html lang={`eng`}
<head>
</head>
<body>
{children}
</body>
</html>
</SessionProvider>
)
}
some protected page
'use client';
import {useSession} from "next-auth/react";
export default function ProtectedPage() {
const {data, status} = useSession()
return (
<div>
{status === "authenticated" ? <div>data.name</div> : null}
</div>
)
}
Is it normal that all pages and components are now rendered on the client? The Next Auth documentation recommends wrapping everything in a provider, but then the main feature of Next.js, namely SSR, no longer works