Setting email_verified to True Using the Auth0 Management API
Last Updated:
Overview
Administrators can update the user profile to set the email_verified attribute to true for a specific subset of users upon their first login. Using the Auth0 Management Application Programming Interface (API) endpoint or a Post-User Registration Action achieves this configuration.
Applies To
- Auth0
- Management API
- Actions
Solution
How is the email_verified attribute set to true using the Management API?
Update the user profile to set the email_verified attribute to true using the PATCH /api/v2/users/{id} Management API endpoint.
PATCH: https://<YOUR_DOMAIN>/api/v2/users/{user_id}
Payload:
{
"email_verified": true
}
How is the email_verified attribute set to true using an Action?
The following Post-User Registration Action example permanently updates the email_verified attribute in the user profile.
NOTE: Depending on the usage of the script, rate-limiting issues may occur. This code is intended as an example and must be tested thoroughly before implementation in a production environment.
exports.onExecutePostUserRegistration = async (event) => {
console.log('ACTION ******* onExecutePostUserRegistration: START *******');
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
});
try {
console.log("user before update: ", event.user);
var params = {
"id": event.user.user_id
};
var data = {
"email_verified": true
}
const userObj = await management.updateUser(params, data, function (err, user) {
if (err) {
console.log("api call error: ", err);
}
});
} catch (e) {
console.log("error: ", e)
}
console.log('ACTION ******* onExecutePostUserRegistration: END *******');
};