Closed jsheffers closed 7 years ago
@jsheffers Yes, this does sound like a CORS issue. Since the login result is successful, and this is in turn feeds into the jDrupal.connect()
(as you noticed, which makes a call off to Drupal requesting new session info) and then the connect mechanism reports it as anonymous. This definitely sounds like a CORS issue then. I personally haven't ran into this issue, but there has been a lot of chatter about CORS in jDrupal's issue queue, as well as DrupalGap's issue queue(s), and I think the solution that folks have arrived at will work in both D7 and D8.
I changed this so that they are on the same domain, and the cookie still won't persist. I have the URL's set up like this:
Angular: example.com:3000 Drupal: example.com
When I call the login function this is the full network tab below. I've blocked out the domain name for privacy purposes.
Call 1:
Call 2:
As you can see here the SET cookie value is working
Call 3:
Any other ideas? I'd love to use this, but I need user authentication to be working. You can also see the withCredentials header in each of the requests, so I don't think that's the issue. Could it be a Drupal 8.3.3 issue?
Ended up adding the following JS to the top of my index.html page.
<script>
window.XMLHttpRequest_ = XMLHttpRequest;
XMLHttpRequest = function(){
var xhr = new window.XMLHttpRequest_;
xhr.withCredentials = true;
return xhr;
}
</script>
I'm using node.js and browserSync to spin up a static server at localhost:3000 which runs my angular application. I then have a Drupal 8.3.3 site setup using MAMP at a vhost "example.com." I'm using the following call in my applications run function and it (Drupal) properly returns me the correct response.
Function call:
When I load my app I get an alert saying "Logged in!" and I see the response in chrome dev tools below:
However, when I alert using this
alert(jDrupal.currentUser().id());
I still get 0, or Anonymous user. Any ideas what could be causing this? Is it a CORS issue?Further background: After looking at the code it looks like jDrupal calls jDrupal.connect() after the login, and the response from that is where I get the anonymous user.