Plugins don't support asynchronous functions
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, react
Research direction
Start by tracing the Fetch API plugin's preRequest hook and the requestOptions function used before the FormEdit component, then follow how Formio.registerPlugin invokes them. Check how the request pipeline handles returned values and Promises. Done means asynchronous plugin callbacks can await token retrieval while the request still proceeds with the modified headers or parameters.
Written by the indexing model from the issue text.
Description
Hi all,
I was looking at the documentation and some other suggestions in the issues list about how to inject new headers to Formio requests (more specifically when you want to use the Resources in a select Data Source Type, for example).
I know that I can set the formioToken and then use x-jwt-token in my backend, which would work fine for me if I didn't need to also have some other params passed along with the request (like location id, warehouse id, etc) that are selected in the frontend.
I tried a few different ways, but none of them worked. After implementing them, when I go to the form builder and select the Resources option in Data Source Type, it just doesn't trigger the http request anymore, if I remove those implementations then it comes back sending the request but, of course, without the headers I want to add.
Here's how I'm doing using Fetch API plugin:
`import { Formio } from 'formiojs';
const FetchPlugin = {
priority: 0,
preRequest: async (url, method, request, formio) => {
// Assuming you can get the JWT token asynchronously from your state
const jwtToken = await asyncFunctionToGetToken();
request.headers.set('Authorization', Bearer ${jwtToken});
return Promise.resolve(request);
},
};
Formio.registerPlugin(FetchPlugin);`
and here's another try using it right before I call the FormEdit component:
Formio.plugins = [{
priority: 0,
requestOptions: function (value) {
// Assuming you already have the token
const jwtToken = state.userReducer.authJWT;
value.headers.append("Authorization", Bearer ${jwtToken});
return Promise.resolve(value);
}
}];
I also tried creating a XMLHttpRequest interceptor, but am having the same symptom.
The versions I'm running are @formio/react 5.3.0 and formiojs 4.17.1
Any ideas I can do that (so I don't need to use the x-jwt-token header) or how can I add new parameters (such location id and some other ids that are referenced in the frontend)?
- Dominant language
- TypeScript
- Stars
- 371
- Forks
- 309
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from formio/react
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
onChange `modified` property remains false when file component is updatedMay be free again @ZenMasterJacob20011 claimed this 295 days ago, and no pull request is open. Open
-
FormBuilder onChange callback not triggered when options prop is providedMay be free again @Victoriya25 claimed this 337 days ago, and no pull request is open. Open
-
FormBuilder with OnChange broke textareaMay be free again @lane-formio claimed this 309 days ago, and no pull request is open. Open
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
milind-soni/OpenMausBot#6730 ·
Maintainers usually reply within 1 day
-
`@angular/[email protected]` depends on vulnerable Vite 7.3.7 - GHSA-p4f5-76q4-ffq7 (Critical RCE)Openarea: @angular/build
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
angular/angular-cli#34764 ·
Maintainers usually reply within 1 day
-
status/need-triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
google-gemini/gemini-cli#30384 · 1 comment ·
Maintainers usually reply within 1 day
-
P2
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day