I'm using the axios-cookiejar-support library.
I have a POST that contains a body, and for some reason, the Cookies aren't getting injected into the request. What did I do wrong here:
return axios
.post(
urlJoin(
config.portal.url,
'Account/Register'),
{
UserName: "[email protected]",
UserFirstName: "First Name",
UserLastName: "Last Name",
Email: "[email protected]",
Password: "...",
ConfirmPassword: "..."
},
{
jar: cookieJar,
withCredentials: true
})
.then(res => callback())
.catch(err => callback(err))
The weird part is, if I perform a GET against the same endpoint the Cookies get passed:
return axios
.get(
urlJoin(
config.portal.url,
'Account/Register'),
{
jar: cookieJar,
withCredentials: true
})
.then(res => callback())
.catch(err => callback(err));
Also, if I perform a POST without a body, they get passed:
.post(
urlJoin(
config.portal.url,
`Account/LoginApi?UserName=${config.portal.userName}&Password=${config.portal.password}`),
null,
{
jar: cookieJar,
withCredentials: true
})
.then(res => callback())
.catch(err => callback(err))
Initialization of Cookie Jar
import axios from 'axios'
import axiosCookieJarSupport from '@3846masa/axios-cookiejar-support'
import tough from 'tough-cookie'
import urlJoin from 'url-join'
const config = require('config');
import { TEST_STATUS_TYPES, TEST_TASK_TYPES } from '../constants/testsConstants'
axiosCookieJarSupport(axios);
const cookieJar = new tough.CookieJar();
cookieJar
? Are you usingsetCookie()
orsetCookieSync()
? – PhlegmaticsetCookie
anywhere. – Cedillo