I’m looking into our documentation on the Pre User Registration flow, and I can see that those Actions run before the user is created on a database. The user doesn’t exist yet so it can not be deleted.
You can reject the user registration with the api.access.deny method by running an action analogically to the one below:
exports.onExecutePreUserRegistration = async (event, api) => {
if (event.request.geoip.continentCode === "NA") {
// localize the error message
const LOCALIZED_MESSAGES = {
en: 'You are not allowed to register.',
es: 'No tienes permitido registrarte.'
};
const userMessage = LOCALIZED_MESSAGES[event.request.language] || LOCALIZED_MESSAGES['en'];
api.access.deny('no_signups_from_north_america', userMessage);
}
};
Please let me if you have any other questions on this topic!
I apologize for the lack of clarity in my explanation.
If the same email address as mine is already registered, I would like to delete that user.
There are other conditions as well, but this is a measure to delete data that has become garbage.
I tried changing the process a bit, but the error still persists.
const auth0 = require("auth0");
exports.onExecutePreUserRegistration = async (event, api) => {
const managementClient = auth0.ManagementClient;
const management = new managementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
scope: `delete:users delete:current_user`,
});
let userId = 'auth0|xxxxxxxxxxxxxxxxxxxx'; // Prepare an ID that exists.
await await management.users.delete({ id:userId }, function (err) {
if (err) {
console.log(err);
}
});
};
ERROR
{
"message": "Insufficient scope, expected any of: delete:users,delete:current_user",
"name": "ManagementApiError",
"stack": "ManagementApiError: Insufficient scope, expected any of: delete:users,delete:current_user\n at UsersManager.parseError (/data/layers/layers-sB3e/sB3eAYbpTrt8QuVtIrpeZvW2ltBQ92kMEYe62vu_j-c/node_modules/auth0/dist/cjs/management/management-client.js:33:16)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async UsersManager.request (/data/layers/layers-sB3e/sB3eAYbpTrt8QuVtIrpeZvW2ltBQ92kMEYe62vu_j-c/node_modules/auth0/dist/cjs/lib/runtime.js:119:23)\n at async UsersManager.delete (/data/layers/layers-sB3e/sB3eAYbpTrt8QuVtIrpeZvW2ltBQ92kMEYe62vu_j-c/node_modules/auth0/dist/cjs/management/__generated/managers/users-manager.js:152:26)\n at async exports.onExecutePreUserRegistration (/data/io/node18-actions/d0da7aea-41aa-43bd-a75c-fadde77fdd42/webtask.js:14:9)\n at async /data/io/83d1a7565435f5e12c048147b30043a0d29de496.js:5:923"
}