In my backend I use set_cookie to set a access token that i need to access in my frontend. but im not able to
My backend using django
# Authentication successful
access_token = AccessToken.for_user(user)
refresh_token = RefreshToken.for_user(user)
response = JsonResponse({'message': 'Login successful', 'tire_stock': tire_stock_data})
# Set HTTP-only flag for both access and refresh tokens
response.set_cookie('access_token', str(access_token), secure=True)
response.set_cookie('refresh_token', str(refresh_token), httponly=True, secure=True)
return response
my frontend using react
const response = await axios.post(
`${import.meta.env.VITE_URL}auth/login/`,
{ username: username, password: password },
{
headers: { "Content-Type": "application/json" },
withCredentials: true,
}
);
the response header
enter image description here
i have tried response.headers[‘access_token’] which returned undefined i also tried document.cookie which didnt work. i read online that i need to expose header to access it? not sure how to do that on django. ChatGPT said i dont need to expose header. I was thinking to pass token in body which would solve it but thats not industry standard since tokens should usually be in headers. so im not sure how to go about it ?