backbone.drupal icon indicating copy to clipboard operation
backbone.drupal copied to clipboard

Update backbone.drupal.js

Open gormus opened this issue 10 years ago • 0 comments

I haven't seen a way to get authenticated user's data. Returning user's uid as status' value, would be much helpful, I think.

// Define auth object, set crossDomain if is necessary
var Auth = new Backbone.Drupal.Auth({crossDomain: true , drupal8: false });

// Request executed in sync mode
var drupal_user_id = Auth.login('admin', 'password');

if(drupal_user_id) {
  console.log('Auth Works');

  var User = new Backbone.Drupal.Models.User({uid: drupal_user_id});
  User.fetch({
    success: function (user) {
      // User attributes.
      console.log('User', user.attributes);
    }
  });

}
else {
  console.log('Auth Error');
}

gormus avatar Jun 27 '15 01:06 gormus