I’ve seen several posts (with outdated links to documentation, incorrect code, etc…) so Hoping someone can simply provide a working solution of code that can be copied/pasted into an Action, that will be Triggered in Post-Login. Like many others, I want to create an Action for ALL users, regardless of the app, that will simply re-send the user another verification email if they login with an Un-verified email address then I’d lke to redirect them to a HTML page that simply says “You need to Verify your Email - please check your in box”. Personally, I do not understand why this is not just a check-box somewhere. I went to this Artice: Send a Verification Email from a Post-Login Action and that code snippet simply does not work.
This code does a simple re-direct:
exports.onExecutePostLogin = async (event, api) => {
if (!event.user.email_verified) {
// Redirect to a custom page or simply show the message.
api.redirect.sendUserTo(“https:///verify-email”);
}
};
so, help me understand why the code necessary to simply send a verification email. It clearly exists already as in Users > (more Actions “there dots”) there is Send Verification Email. Can that please be shared?
You can only trigger an email by using an endpoint with an action. I reviewed the script, and it looks correct to me. If it is not working, you can write your own logic to trigger this. I also verified that the above code passes as well. You can use the access.deny method to deny access if the user’s email is not verified.
You mentioned the script is not working, you may missed to set Client ID and secret in Auth0 actions to run the action. Review the code and let me know if you still faced any issues.
Thank you for posting your question. It’s a great idea to introduce this kind of checkbox in the dashboard in a plug-and-play fashion. I encourage you to open a new thread in the Feedback category with your use case explained. However, you can achieve a similar experience by using Forms with a post-login action to check if the user’s email is verified, render a proper form, and allow or deny access to your application.
In the Forms, you’ll need only a Step with a Text or rich text attribute that tells your users to Verify their email addresses. Within an Action, you’ll check if the user’s email address is verified and, based on that, render a form informing your users to check the inbox. In the onContinuePostLogin, you can conditionally deny access to your application if the user email is still unverified or apply your logic here.
The Template for Actions is a library of prebuilt Auth0 Developer solutions that you can adjust to your needs. Your Custom Action sits under Actions->Triggers->Post-Login → Custom, from which you can drag and drop it into your flow.
For the 2nd email coming from the Tenant address, make sure to pass the client_id in the job request inside your action as if you won’t send it, Auth0 will use the global Client ID. → Auth0 Management API v2