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?