Home > OS >  Destructuring 'req.body.data' into 'req.body'
Destructuring 'req.body.data' into 'req.body'

Time:12-19

I am sending some data from the front end to the back end. I am trying to send data as an object to the back. When it arrives, it is obviously req.body.data, but should land in the backend as req.body. How do I destructure the request, either from the front or the back so that the back only receives req.body

front end

const { user } = await axios.post('http://localhost:3000/auth/signup', {data});

Backend (what I want)

if(req.body.type === 'vendor') {

Right now the backend received (What i dont want)

if(req.body.data.type....)

CodePudding user response:

Your passing data as an object prop. Just pass it directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', data)

CodePudding user response:

You are sending object with data property when sending request to the backend. What you should do is destruct that data object and send its property directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', { ...data });
  • Related