How to add global headers with `onRequest` when using $fetch.create
See original GitHub issueWith axios, one can add global headers to config just like below
const instance: AxiosInstance = axios.create({
baseURL: baseUrl,
withCredentials: true,
});
// Add a request interceptor
instance.interceptors.request.use(
function (config) {
const token = ls.getItem("alva.accessToken");
config.headers = {
Authorization: `Bearer ${token}`,
};
return config;
},
function (error) {
return Promise.reject(error);
}
);
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:6
Top Results From Across the Web
fetch() does not send headers? - Stack Overflow
I have tried to create Request and specifically add headers using req.headers.append() . The headers still wouldn't send. javascript · http ...
Read more >How to set request headers in fetch? - RapidAPI
How to set request headers in fetch? · → STEP #1. We need an API that we can call to learn how to...
Read more >Using Axios to set request headers - LogRocket Blog
In this article, we examined how to set HTTP request headers with Axios by passing an object, creating a specific Axios instance, and...
Read more >Using the Fetch API - MDN Web Docs
To cause browsers to send a request with credentials included on both same-origin and cross-origin calls, add credentials: 'include' to the init ...
Read more >unjs/ofetch: A better fetch API. Works on node ... - GitHub
We use conditional exports to detect Node.js and automatically use unjs/node-fetch-native. If globalThis.fetch is available, will be used instead.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Another example to re-use other headers:
i think this can overwrite else headers