Get username from uid


  • 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.

  • GNU/Linux Admin

    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

Log in to reply
 

Suggested Topics

| |