Answers for "interceptors"

-1

interceptors

const api = axios.create({
  baseURL: '/',
  headers: {
    'Content-Type': 'application/json'
  },
})
api.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token')
    if (token) {
      config.headers['Authorization'] = `Token ${token}`
    }
    return config
  },
  error => Promise.reject(error)
)
export default api
Posted by: Guest on December-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language