Next-Auth in server rendered components aka appDir pages

how do we deal with next-auth in appDir? I am genuinely curious, as I am trying to migrate from pages to app but using next-auth you have to wrap the app in the SessionProvider, which isn't ideal to do in the layout component, making all its children client components. So is there any nice solution yet?
2 Replies
Sebastian
SebastianOP2y ago
I was mainly wondering how can we get the current user in a request. I digged very little in the getServerSession from next-auth/next and saw that for server components, they take the cookies from the head using next/head and then are able to authenticate the user and return a valid session. Just if anybody was wondering that. You just need to pass the authOptions object to the getServerSession
cje
cje2y ago
Yea that’s the correct answer If anyone finds this because their users don’t have IDs on them or are behaving weirdly in some other way: you probably forgot to pass authOptions
Want results from more Discord servers?
Add your server