JavaScript by Patrik

Make Axios send cookies

Make Axios send cookies in its requests automatically.

You can use the withCredentials property.

axios.get(BASE_URL + '/todos', { withCredentials: true });

Also it is possible to force credentials to every Axios requests

axios.defaults.withCredentials = true

Or using credentials for some of the Axios requests as the following code

const instance = axios.create({
   withCredentials: true,
   baseURL: BASE_URL
})
instance.get('/todos')

Comments