[Vuejs]-Vue.js POST 400 (Bad Request)

0👍

Assuming that authHeader() only returns an object with the Authorization key, you are missing the required Content-Type header to identify the request body as JSON

const requestOptions = {
  method: "POST",
  headers: {
    ...authHeader(),
    "content-type": "application/json", // 👈 added header
  },
  body: JSON.stringify(sample),
};

On the server-side, you also need to ensure you have the correct middleware for handling JSON request bodies

app.use(express.json());

Leave a comment