Next.js Discord

Discord Forum

NextAuth with app router, _app equivalent?

Unanswered
Giant Angora posted this in #help-forum
Open in Discord
Giant AngoraOP
Hey everyone,

I'm migrating to the app router and I was wondering what the equivalent of putting the SessionProvider in the _app.tsx is: https://next-auth.js.org/getting-started/example#configure-shared-session-state

Do I just wrap it inside the layout.tsx in app?

8 Replies

Giant AngoraOP
If I do so I just end up with an error stating that the context isn't available on server components, which makes sense, but if I were to set the layout component to a client component wouldn't that defeat the whole point of the server components? 😅
American black bear
no, but its good to have the layout as cliente component, so you can create something like this
and you call the componente from the layout
Masai Lion
its fine to do, you just can't use useContext hooks in server components, but any client component can still use the hook then
also for next-auth, you should upgrade to v5 which has full support for server components https://authjs.dev/guides/upgrade-to-v5
Giant AngoraOP
Thank you guys! @American black bear @Masai Lion