nextjs api route request.query is undefined

export async function GET(
req: NextApiRequest,
res: NextApiResponse<GoogleOAuthCodeExchangeApiResponse>
) {
console.info(`request query ${req.query}`)
const code = req.query.code
export async function GET(
req: NextApiRequest,
res: NextApiResponse<GoogleOAuthCodeExchangeApiResponse>
) {
console.info(`request query ${req.query}`)
const code = req.query.code
logs:
request query undefined
request query undefined
I followed the docs and req.query should be {} by default but here is undefined, why?
Solution:
If you're using the App Router, the req type is NextRequest, or even just simply Request. query doesn't exist on the requests from App Router.
Jump to solution
2 Replies
Solution
Ironmate
Ironmate5mo ago
If you're using the App Router, the req type is NextRequest, or even just simply Request. query doesn't exist on the requests from App Router.
Giuliopime
Giuliopime5mo ago
yep just figured it out, were looking at the wrong docs
Want results from more Discord servers?
Add your server