Nothing’s wrong on your end, the app_metadata is not presently available to Hooks out of the box. Apologies for the misleading information, we will get that documentation corrected. We do intend to make it available eventually, but I do not have an ETA on that change.
In the meantime, you can use the Management API to access this information. It’s a bit more involved, but I did test this out myself and was able to get at the app_metadata for a newly created user. This example code was inspired by Use the Management API in rules. But since we’re working in a Hook the example below must first obtain an access_token (Get an access token).
important: you can set your client_id, client_secret, and domain as webtask secrets by clicking the wrench icon -> secrets in the top left corner of the hook editor. That will safely make them available as shown in this code snippet. These credentials need to be for a Non Interactive Client with access to your Auth0 Management API.
// example hook accessing app_metadata via the Management API
module.exports = function (user, context, cb) {
var request = require('request');
var ManagementClient = require('auth0@2.6.0').ManagementClient;
var domain = context.webtask.secrets.domain;
var options = {
method: 'POST',
url: 'https://' + domain + '/oauth/token',
headers: { 'content-type': 'application/json' },
body: {
grant_type: 'client_credentials',
client_id: context.webtask.secrets.client_id,
client_secret: context.webtask.secrets.client_secret,
audience: 'https://' + domain + '/api/v2/'
},
json: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
var management = new ManagementClient({
token: body.access_token,
domain: domain
});
management.getUser({ id: 'auth0|' + user.id }, function (err, enrichedUser) {
// Access app_metadata with enrichedUser.app_metadata
});
});
cb();
};
Let me know how that works out for you, or if you have any questions getting it all set up.