Categories
JavaScript Answers

How to make Axios send cookies in its requests automatically?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *