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)
}
};
tyf
February 8, 2024, 11:40pm
2
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 .
Problem statement: How do I add custom claims to an Access and/or ID Token with Actions?
Solution: Custom claims can be added to an Access/ID Token in a namespaced format by utilizing a Post Login Action . For example:
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
const { favorite_color, preferred_contact } = event.user.user_metadata;
if (event.authorization) {
// Set claims in ID token
api.idToken.setCustomClaim(`${namespace}/f…
Thanks, i have a question can writing properties generate additional costs?
1 Like
tyf
February 9, 2024, 1:46am
5
As far as I’m aware adding custom claims/metadata will not cause you to incur additional costs.
1 Like
system
Closed
February 23, 2024, 1:46am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.