I want to re-send the verify email to users who login, and have not yet verified their email.
I’ve configured a new Machine to Machine application, accordingly to the steps illustrated in this post, and given the new application access to update:users
scope.
I deployed a new action with this code:
const { ManagementClient } = require('auth0');
/**
* Handler that will be called during the execution of a PostLogin flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const { user } = event;
if (!user.email_verified) {
const client = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
});
try {
await client.sendEmailVerification({ user_id: user.user_id });
console.log('Verification email resent for user:', user.email);
} catch (error) {
console.error('Failed to resend verification email:', error);
}
}
};
When I test it, I don’t receive any email (checked Spam folder as well).
Here, I read that I should be able to see a new section, called “Action details” in the Monitoring / Logs page for successfull logins; but this is not the case for me. This didn’t change also after I deployed a simplified version of the action:
exports.onExecutePostLogin = async (event, api) => {
console.log("My custom action is running");
};
I also tested the core functionality of the action locally, with the function you can see below:
const { ManagementClient } = require("auth0");
async function test () {
const client = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
});
try {
await client.sendEmailVerification({ user_id: "********" });
console.log("Success!");
} catch (error) {
console.error("Error:", error);
}
};
test();
… and in this case I was able to receive the email; so it really seems like the action code is not running; any idea why this could be the case? Or how could investigate this further?
Any help is appreciated - thank you.