Problem statement
Is it possible to always set email_verified to true for a certain subset of users when they first log in?
Solution
It is possible to update the user profile to set the email_verified 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
}
Here is a post-registration Action example that will permanently update the user’s email_verified in the user profile:
https://auth0.github.io/node-auth0/ManagementClient.html#updateUser
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 *******');
};
It should be noted that depending on the usage of the above script, this may cause issues with rate limiting.
Please note that this code is just to be used as an example and should be tested thoroughly before you push it to production.