Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
My cookies are not setting, when i make request in insomnia my cookies are set

When i send request in Insomnia cookies are set, but on client (Vue) i make request to my backend (django) cookies are not set

Expected Behaviour: Cookie is set

Actual Behaviour: Response status is 200, but the cookies is not set and shows only in developer tools int the network tab

Vue request:

    methods: {
    loginUser: function () {
      fetch(`http://127.0.0.1:8000/auth/login/`, {
        method: "POST",
        headers: {
          "content-type": "application/json",
        },
        credentials: 'include',
        body: JSON.stringify({
          username: this.username,
          password: this.password,
        }),
      })
        .then((res) => {
    
          return res.json();
        })
        .then((data) => {
           window.location.replace(data.url);
    
        })
        .catch((err) => console.error(err));
    },

Django EP:

@csrf_exempt
def loginUser(request):
    if not request.method == "POST":
        return HttpResponse(status=405)
    data = json.loads(request.body.decode('utf-8'))
    user = authenticate(request, username=data['username'], password=data['password'])
    request.session.set_test_cookie()
    if user is not None:
        login(request, user)
        return HttpResponse(json.dumps({'url': 'http://localhost:8081/#/notes'}))
    else:
        print('Invalid login')
        return HttpResponse(status=404)
  • test cookie not working (request.session.set_test_cookie())
def getloggeduser(request):    
    print(request.session.test_cookie_worked())
    return JsonResponse({'name': ''})

my setting:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'notesapp.apps.NotesappConfig',
    'authentication.apps.AuthenticationConfig',
    'corsheaders',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!