Answer the question
In order to leave comments, you need to log in
Axios config object is possibly 'undefined'?
const $api = axios.create({
withCredentials: true,
baseURL: API_URL,
})
$api.interceptors.request.use((config:AxiosRequestConfig) => {
config.headers.Authorization = `Bearer ${localStorage.getItem('token')}`
return config
})
Answer the question
In order to leave comments, you need to log in
(config.headers ??= {}).Authorization = `Bearer ${localStorage.getItem('token')}`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question