Django doesn't receive cookies from request

Viewed 147

I'm working on a Nuxt/Vue app that uses Django on the backend. I'm using the standard Django Session authentication. The problem with my code is that the user's are always logged out, according to Django, because Django doesn't see any cookie in the request.

Basically i created an API endpoin that should return whether or not the user is authenticated, but since Django doesn't see any sessionid cookie in the request, the user will always be unauthenticated to the backend.

def checkAuth(request):
  print(request.COOKIES)
  response = {'state': str(request.user.is_authenticated), 'username': str(request.user)}
  return JsonResponse(response, safe=False)

If i print request.COOKIES it returns {}.

Here is how i send the request from the frontend, where i'm using Axios:

return axios({
  method: 'get',
  url: 'http://127.0.0.1:8000/checkAuth',
  withCredentials: true,
}).then(function (response) {
  console.log(response)
}).catch(function (error) {
  console.log(error)
});

The problem should not be from the frontend, since on Chrome i can see the session cookie and the csrf cookie correctly. I already tried to disable any possible CORS security setting on Django. The frontend is running on 127.0.0.1:3000 and the Django app on 127.0.0.1:8000.

Why doesn't Django see the cookies? Any kind of advice is appreciated

0 Answers
Related