Failed to compile when using NextAuth directly in the layout.tsx because of the following error.
Error: React Context is unavailable in Server Components
Fix
SessionProvider from next-auth/react only works in client component, not the server component. Therefore, make the AuthProvider with use client on top and import the component inside the layout.tsx
Issue
Failed to compile when using
NextAuth
directly in thelayout.tsx
because of the following error.Fix
SessionProvider
fromnext-auth/react
only works inclient component
, not theserver component
. Therefore, make theAuthProvider
withuse client
on top and import the component inside thelayout.tsx