How to set a custom property in a user using actions? I want to add a property called "blockedUser"

I want to add a property called “blockedUser” when the user do the first login and the amount of active users is above 500. This is my action code.
The user is already denied, but if he login again it will be 2 logins in the count and the action will fail.

exports.onExecutePostLogin = async (event, api) => {

const ManagementClient = require(‘auth0’).ManagementClient;
const management = new ManagementClient({
MYCONFIGS…
});

const activeUsers = await management.getActiveUsersCount();

const params = {
search_engine: ‘v3’,
q: email:"${event.user.email}"
};

try {
const users = await management.getUsers(params);
if (activeUsers > 500 && users.length == 1 && event.stats.logins_count == 1) {
// management.users.delete({ id: event.user.user_id })
// i want to add the custom property here
api.access.deny(‘many-users’, ‘We already have our max user capacity’);
}
} catch (e) {
console.log(e)
}

};

Hey @rhuan.carvalho !

This sounds like something that could be done by either adding a custom claim to token(s) OR updating a user’s metadata.

Thanks, i have a question can writing properties generate additional costs?

1 Like

As far as I’m aware adding custom claims/metadata will not cause you to incur additional costs.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.