api.getSession in pages router
Hi!
How should I fetch the session server-side (
getServerSideProps or API route) when using Next.js' pages router? Both of these seem to work but they give TypeScript errors:
Thank you!2 Replies
Not 100% sure if there is any other way to do this. I can't find any underlying raw request attached to the NextApiRequest to find the native Headers object, so you can just manually make it.
Maybe extract that into a
toHeaders util.
Or you could use app router for just api requests and have access to NextRequest and NextResponse which has a headers attribute the perfect type (or pass in the entire request). I'd imagine you wouldn't want to thoughGood enough for me, thank you so much!