I have jwt user auth token that I am trying to set for the Authorization header to Axios GET request. But it is not set. Backend shows undefined and firefox dev tools don't show any Authorization header set for HTTP request. Same token and same helper function sets the header for POST request and backend reads it correctly.
const setAuthHeader = user => {
return { headers: { Authorization: `Bearer ${user.token}` } }
}
GET doesn't set header
export const getWeights = async user => {
try {
const resp = await axios.get(
baseUrl,
{ userId: user.id },
setAuthHeader(user)
)
return resp.data
} catch (error) {
console.log(`error`, error)
}
}
POST sets header
export const postWeights = async (user, weight, date) => {
try {
const resp = await axios.post(
baseUrl,
{ userId: user.id, weight, date },
setAuthHeader(user)
)
return resp.data
} catch (error) {
console.log(`error`, error)
}
}