Add hook for post registration

I am trying to add a hook for post registration and trying to assign default role on the sign up. But I am getting error saying access_denied: {“error”:“access_denied”,“error_description”:“Unauthorized”}.

module.exports = async function(user, context, cb) {
var ManagementClient = require(‘auth0’).ManagementClient;
const auth0 = new ManagementClient({
domain: ‘’,
clientId: '
’,
clientSecret:
‘***,
scope: ‘update:users’,
audience: '
’,

});

// Get roles and select the correct one.
let customerRoleId;
const roles = await auth0.getRoles().catch(err => {
console.log(’—errInside get Roles method—’, err);
});
console.log(’–roles–’, roles);
for (const role of roles) {
if (role.name === ‘employer’) {
customerRoleId = role.id;
break;
}
}

// Assign the default role to user
await auth0
.assignRolestoUser({ id: user.id }, { roles: [customerRoleId] })
.catch(err => {
console.log(’—errInside assignRolestoUser—’, err);
});
cb(null, user, context);
};

Hey there!

You’re getting that error once you try to save hook code?