I'm hosting a django site locally. If baseQuery has relative path like that baseQuery: fetchBaseQuery({ baseUrl: '/api' })
, then session id is sent inside headers automatically
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken')
}
if front-end and back-end parts are hosted on different ports and the path in baseQuery is absolute fetchBaseQuery({ baseUrl: 'http://localhost:8000/api' })
(while React is running on:3000) then session id is not attached to requests and Django sends a new one with every response. Is it normal behaviour and how can it be changed?
Turns out it's enough to add credentials: "include"
like that
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8000/api', credentials: "include" })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.