I have a function that sends a JWT validation request:
const sendValidateJWTRequestFetch = (url: string, token: string) =>
fetch(url, {
method: 'GET',
mode: 'cors',
headers: {
Authorization: token,
'Access-Control-Allow-Origin': '*'}
})
.then(response =>
response.ok ? response : Promise.reject<Response>(response)
)
.then(response => response.json())
.then(data => data.Token)
While it works fine in my development environment, I'm facing some CORS issues in production. To resolve this, I want to switch to using axios
for the get
request. Here's what I have tried:
const sendValidateJWTRequest = (url: string, token: string) =>
axios.get(url, {
headers: {Authorization: token, 'Access-Control-Allow-Origin': '*'},
crossDomain: true
})
.then(resp => resp.data ? resp : Promise.reject<Response>(resp))
.then(response => response);
However, I am encountering an error while working with TypeScript. The error can be viewed here. How can I resolve this issue?
In order to enable crossDomain: true
, I had to make the following addition to the code:
declare module 'axios' {
export interface AxiosRequestConfig {
crossDomain: boolean;
}
}