form-auto-content
form-auto-content copied to clipboard
Cannot add JWT Bearer token to a form
Form options not taking into consideration, options passed Sample Code:
const option = {
headers: {
Authorization: `Bearer ${jwtToken}`,
},
payload: {
'content-type': 'multipart/form-data',
},
}
const form = formAutoContent(
{
file: fs.createReadStream(`./test/fixtures/test.txt`),
},
option,
)
Rest API call never will get JWT as it's not passed to request
Wrong usage of the API:
const form = formAutoContent(
{
file: fs.createReadStream(`./test/fixtures/test.txt`),
})
const myHeaders = {
...form.headers, // the content-type is already added automatically
Authorization: `Bearer ${jwtToken}`
}
const thePayloadToSubmit = form.payload
The option object lets you to change the output field names:
const form = formAutoContent(
{
file: fs.createReadStream(`./test/fixtures/test.txt`),
}, { payload: 'FOOO', headers: 'BAR' )
const myHeaders = {
...form.BAR, // the content-type is already added automatically
Authorization: `Bearer ${jwtToken}`
}
const thePayloadToSubmit = form.FOOO
I think we may trigger an error when the input options does not contain a valid string value (as in this case, an object was provided)