How to make Axios send cookies in its requests automatically?

Sometimes, we want to make Axios send cookies in its requests automatically.

In this article, we’ll look at how to make Axios send cookies in its requests automatically.

How to make Axios send cookies in its requests automatically?

To make Axios send cookies in its requests automatically, we can set the withCredentials option to true.

For instance, we write

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

to call axios.get with an object that has withCredentials set to true to send the cookie with the request to BASE_URL + '/todos'.

Conclusion

To make Axios send cookies in its requests automatically, we can set the withCredentials option to true.