Next.js Discord

Discord Forum

FormData returns an empty object?

Answered
Samoyed posted this in #help-forum
Open in Discord
SamoyedOP
So i have a form with one field (email) that runs one of my route handlers at auth/signin when submitted. I read the docs on form data and have just this in my route.js rn
import { NextResponse } from "next/server";
 
export async function POST(request) {
  const formData = await request.formData()
  console.log(formData)
  return NextResponse.json({formData})
}

This returns an empty json object like this
{
  formData : { } 
}

even though in my console, im pretty sure the form data is logged correctly but i cant really parse what it is, whats the Symbol(state) thing?
FormData {
  [Symbol(state)]: [ { name: 'email', value: 'myemail@gmail.com' } ]
}


So, I literally just need to extract that email from there so i can use for auth stuff. Thats all. Please help, its been hours.
Answered by joulev
formData is not a JSON object. Try const name = formData.get("name")
View full answer

8 Replies

Answer
@joulev `formData` is not a JSON object. Try `const name = formData.get("name")`
SamoyedOP
Wow, thank you. Id like to point out tho that this was right from the nextjs docs so I just assumed they knew what they were doing
I also wasnt familiar with FormData as a type so ig i need to check out its methods
@Samoyed Click to see attachment
Oh… they certainly made a mistake here. Could you file a documentation bug report?
@joulev Oh… they certainly made a mistake here. Could you file a documentation bug report?
SamoyedOP
Cant say ive done that before, ill look into it
Um. Otherwise tomorrow I’ll file an issue for you, this is definitely wrong