Search code examples
node.jsexpressstormpath

Can I access the custom data of a specific user with Stormpath?


I am using Stormpath with Express and I want to access custom data of a specific user that exists in the database while not logged in as that user. This will be used in an admin-style UI where users with certain privileges can edit the custom data of other users.

How can I access the data of a specific user like I would access the current user's data using req.user.customData?


Solution

  • If you're using the express library you can do it by saying:

    app.get('stormpathApplication').getAccount(account_href_here, function(err, account) {
      if (err) throw err;
      account.getCustomData(function(err, data) {
        if (err) throw err;
        console.log(data);
      });
    });
    

    app.get('stormpathApplication') is an Application object under the hood, so any of these API docs work on it: http://docs.stormpath.com/nodejs/api/application

    I'm the developer of this library, hope this helps!