This is my code:
export async function GET(req) {
try {
const email = await req.query.email;
if (!email) {
return NextResponse.json({ message: "Email query parameter is required." }, { status: 400 });
}
return NextResponse.json({ message: `Email received: ${email}` }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ error: error, message: "Encountered an error" }, { status: 500 });
}
}
But for some reason, the value of email is always undefined. The API endpoint I'm using is /api/[email protected]. I don't have any config for bodyParser. I even tried adding the config but still returning as undefined. But for some reason, from the same file, POST function works fine using await req.json().
I've been dealing this for days and I don't know why it's returning as undefined. I tried checking req.query but still undefined.
Thank you in advance