The story goes like this. We were calling cross-origin API. When logged in, the preflight request is sent during API call; weirdly, when logged out, the preflight request is not sent. Also, the preflight request was failing, and so during the logged-in state, the request failed.
And the more weird thing is people were adopting some weird solution of expiring the session and then making requests. This results in not sending the Preflight request. Hence (huh..) hack for them.
For all those who don’t know aboutpreflight request
, Visit
this.GET
.OPTION
method and this is handled differently.
Well, this part is of no interest, about like Why?, but the interesting thing is
the response doesn’t contain headers like Access-Control-Allow-Origin
,
Access-Control-Allow-Headers
, Access-Control-Allow-Methods
etc.axios
axios
sets some headers from the cookie itself and X-XSRF-TOKEN
is one of
them. So X-XSRF-TOKEN
header was sent during the logged-in state by axios
,
this results in a preflight request and hence the failure. After manual session
expiration, the X-XSRF-TOKEN
cookie was deleted, hence the successful request.X-XSRF-TOKEN
header in the API
requestOPTION
method.