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

183
Views
drupal user/login_status endpoint not working with js fetch

Here is my problem : I try to know if user is logged-in with drupal endpoint user/login_status. It work fine if my js fetch request come from the same domain. It means that if user is logged-in, the answer is "1" and "0" if not. But it doesn't work if it comes from localhost:3000. The answer is always 0 without any error. I know it's certainly a cors problem but I can't find the solution.

Here is my code :

fetch(`${this.url_server}user/login_status?_format=json`, {
      method: "GET",
      headers: {
        "Content-Type": "application/json"
      }
    })
      .then(response => {
        return response.text()
      })
      .then(data => {
        
        console.log("login status", data);//.current_user
        return data;
      }).catch(error => {error.log(error)});

My services.php file :

cors.config:
    enabled: true
    # Specify allowed headers, like 'x-allowed-header'.
    allowedHeaders: ['x-csrf-token', 'authorization', 'content-type', 'accept', 'origin', 'x-requested-with']
    # Specify allowed request methods, specify ['*'] to allow all possible ones.
    allowedMethods: ['POST', 'GET', 'OPTIONS', 'DELETE', 'PUT', 'PATCH']
    # Configure requests allowed from specific origins.
    #allowedOrigins: ['*']
    allowedOrigins: ['http://localhost/','http://localhost:3000','http://localhost:3001','http://localhost:3002','*']
   # Sets the Access-Control-Expose-Headers header.
    exposedHeaders: false
    # Sets the Access-Control-Max-Age header.
    maxAge: false
    # Sets the Access-Control-Allow-Credentials header.
    supportsCredentials: false

And my apache conf file :

 <Directory "/home/bob/dev/test/web">
                Allowoverride All
                DirectoryIndex index.php
                Options FollowSymLinks
                Require all granted
                Header set Access-Control-Allow-Origin "*"
        </Directory>

Any idea?

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!