Axios: Cookies not send automatically with post request!

Created on 7 Sep 2017  ·  3Comments  ·  Source: axios/axios

Summary:
Cookies received in previous _get_ call not send with following _post_ command.

Details:
I am using the following sequence of calls to login into the backend.

axios.get(Url.csrfToken(), { withCredentials: true })
            .then(response => response.data)
            .then(token => axios.post(Url.authenticate(), { username, password }, {
                    headers: {
                        'content-type' : 'application/x-www-form-urlencoded',
                        'crsf-token' : `${token.csrfToken}`
                    },
                    withCredentials: true
                })
            )
            .then(response => console.log('completed'))
            .catch(error => console.log(error))

Cookies returned in set-cookie in response headers for _get()_ is required by _post()_.

But post() does not have any cookie in its header, leading to failure.

How could I fix it, please help?

Environment

  • react: 16.0.0-alpha.12
  • react-native: 0.47.2
  • iOS Simulator - version 10.0

Most helpful comment

is this helpful?

https://stackoverflow.com/questions/46288437/set-cookie-header-has-no-effect

On Mon, 25 Sep 2017 at 22:28, Chris Gillis notifications@github.com wrote:

Also curious


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mzabriskie/axios/issues/1076#issuecomment-332002134,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVepSmu6HPCE7R-bdBHXU4wa12co56ekks5smAzWgaJpZM4PPYy9
.

All 3 comments

@varmeh How did you fix this?

Also curious

is this helpful?

https://stackoverflow.com/questions/46288437/set-cookie-header-has-no-effect

On Mon, 25 Sep 2017 at 22:28, Chris Gillis notifications@github.com wrote:

Also curious


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/mzabriskie/axios/issues/1076#issuecomment-332002134,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVepSmu6HPCE7R-bdBHXU4wa12co56ekks5smAzWgaJpZM4PPYy9
.

Was this page helpful?
0 / 5 - 0 ratings