'Error in setting headers in axios and react
I have tried many of the stack overflow solution but I am unable to solve this problem
My code is below
helper/axios.js
import axios from "axios";
const instance = axios.create({
baseURL: process.env.REACT_APP_BACKEND_URI,
timeout: 1000,
headers: {},
});
export default instance;
App.js
import axios from "./helper/axios";
const { user } = useAppSelector((state) => state);
axios.interceptors.request.use((config: any) => {
if (user.isLoggedIn) {
config.headers.authorization = user.accessToken;
config.headers["x-refresh"] = user.refreshToken;
console.log(config);
}
return config;
});
[Image of console] [1]: https://i.stack.imgur.com/fWAIb.png
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
