Get username from uid

NodeBB Development
  • I'm writing a plugin that uses the action:post.save hook
    I've got the plug-in logging the post data to the console fine.

    Im then trying to fetch the username from the uid from the post data.
    my basic library.js is:

    var User = module.parent.require('./user';);
    module.exports.emailalert = function(postData) {
    console.log(postData.uid); // this is returning '2'
    User.getUserField(postData.uid, 'username', function(data){
    console.log(data); // this is returning 'null'
    });
    };
    

    however User.getUserField is returning null.
    User module is definitely getting called.

  • Hey @cadack! That method is error-first, so give this a shot:

    User.getUserField(postData.uid, 'username', function(err, username) {
        console.log(username);
    });
    

    You could also try the method User.getUsernamesByUids

  • @julian how did I miss that! Cheers buddy


Suggested Topics


  • 0 Votes
    3 Posts
    248 Views
  • 1 Votes
    3 Posts
    381 Views
  • 0 Votes
    6 Posts
    1007 Views
  • 0 Votes
    3 Posts
    1491 Views
  • 0 Votes
    10 Posts
    2149 Views