Unified types for getServerSideProps and api endpoints #14311
Unanswered
benjamintd
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I am using the following pattern for some pages:
SWR calls an api endpoint which takes
(req: NextApiRequest, res: NextApiResponse)
as arguments.Meanwhile, getServerSideProps uses a context which contains "vanilla"
req, res
arguments (with typesHTTPIncomingMessage
andHTTPResponse
).This prevents code reuse between my API handler and getServerSideProps, especially concerning authentication since I am using the
nextjs-auth0
library which expectsNextAPIRequest
andNextApiResponse
arguments.My questions are the following:
req, res
arguments to have different types, or could thegetServerSideProps
context be augmented to have a similarreq, res
signature?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions