Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add JWT Bearer token to a form #23

Open
gt-mj-1107 opened this issue Jun 26, 2023 · 1 comment
Open

Cannot add JWT Bearer token to a form #23

gt-mj-1107 opened this issue Jun 26, 2023 · 1 comment
Labels
good first issue Good for newcomers invalid This doesn't seem right

Comments

@gt-mj-1107
Copy link

gt-mj-1107 commented Jun 26, 2023

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

@Eomm
Copy link
Owner

Eomm commented Jun 26, 2023

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)

@Eomm Eomm added good first issue Good for newcomers invalid This doesn't seem right labels Jun 26, 2023
@Eomm Eomm closed this as completed Nov 2, 2023
@Eomm Eomm reopened this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants