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
Ironmate8mo 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
GiuliopimeOP8mo ago
yep just figured it out, were looking at the wrong docs

Did you find this page helpful?