I am creating my django react app. I would like to make authentication via Cookie just like in Django oscar documentation.
But when i send my post request i get a new session id with every request. I am using axios with credentials.
Its my base.py
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'oscar.apps.basket.middleware.BasketMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
]
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = [
"https://example.com",
"https://sub.example.com",
"http://127.0.0.1:8000",
"http://localhost:3000",
"http://localhost:8000",
"http://127.0.0.1:9000",
"127.0.0.1"
]
And this is my Post requests
import axios from "axios"
import Bar from './Bar';
import BasketItem from './BasketItem'
import "../css/basket.min.css"
const session = axios.create({
withCredentials: true
});
const configAxios = {
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Credentials': true,
},
};
const Basket = props => {
const [countries, setCountries] = useState([]);
const [load, setLoad] = useState(false);
const [error, setError] = useState('');
const [array, setArray] = useState([]);
useEffect(() => {
const data = {
url: "http://127.0.0.1:8000/api/products/22/",
quantity: 1,
}
session.post('http://127.0.0.1:8000/api/basket/add-product/',data)
.then(res =>{
console.log(res.data)
console.log("Cookies are ", document.cookie)
})
session.post('http://127.0.0.1:8000/api/basket/add-product/',data)
.then(res =>{
console.log(res.data)
console.log("Cookies are ", document.cookie)
})},[])
And this is results of my requests

So if you can see sessionid values are different instead of being the same and its provide to 401 error.
