Hi,

I am building my app using vue.
i am trying to use jdrupal as its seems very good but its showing undefined whenever i tried to console anything.

1) my drupal path is :: http://localhost/d8angular/drupal8/web/
2) vue running on local port

3) on cusotm js ::
i defined my site path but everything is undefined::
jDrupal.config('sitePath', 'http://localhost/d8angular/drupal8/web');
jDrupal.connect().then(function() {
var user = jDrupal.currentUser();
var msg = user.isAuthenticated() ?
'Hello ' + user.getAccountName() : 'Hello World';
console.log(user.getAccountName());
});

i checked header jdrupal.min script is there

i.e.

i am unable to find what's wrong it it as documentation says just include js & get the data?
can you help me out?

thanks

CommentFileSizeAuthor
#3 jd2.PNG38.26 KBdrupalprog
#3 jd1.PNG603.82 KBdrupalprog
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drupalprog created an issue. See original summary.

tyler.frankenstein’s picture

Category: Bug report » Support request
Priority: Critical » Normal

ts showing undefined whenever i tried to console anything.

I don't fully understand. Will you please clarify with your console statements and any other code?

drupalprog’s picture

FileSize
603.82 KB
38.26 KB

Hi tyler,

thanks for replying.

sorry for the confusion
as i am saying whenever i tried to console user uid, role , username whatever
but its always console uid =0, role= anonymous.

I am logged in as admin on my drupal website on same browser but it always showing anonymous user.

i am attaching two screenshot that showing console of jdrupal(in vue) & drupal in which i logged in as admin but still showing anonymous user.

thanks

tyler.frankenstein’s picture

You're likely experiencing a CORS issue. For example, your Drupal site is running out of http://localhost/d8angular/drupal8/web and the app is running out of http://localhost:8080

These are two different domains, and browsers by default protect against this (cross origin resource sharing).

If you move your app to run out of http://localhost/d8angular/drupal8/web/app that should fix it, otherwise you'll have to configure your Drupal site and webserver for CORS.

drupalprog’s picture

Hi,

I already set cors on service.yml on drupal end
also i tried set a app inside drupal like you suggested
http://localhost/d8angular/drupal8/web/app
but same issue i got uid=0.

one more i need to point out ..if i have cors then i should not access drupal site but i got data via rest from drupal & its showing on
app too(on banner its dynamic data showing from drupal block)?

can you suggest what i need to do?

thanks

drupalprog’s picture

Hi,

if i try to load node then its showing the node title in console
but not related to user
jDrupal.nodeLoad(1).then(function(node) {
console.log( node.getTitle());
});

do you think its a issue to get current user logged(i.e. jDrupal.connect())?

i did some more debugging & found when i use your rest api path in vue i.e
http://localhost/d8angular/drupal8/web/jdrupal/connect?_format=json
then its showing same uid=0
& when i hit this in same browser then its showing uid=1 with role=admin

thanks

drupalprog’s picture

Hi,

Any reply?

thanks

tyler.frankenstein’s picture