Require Email Verification Before Signing In

Hello, I want to require email verification before signing in. If the user tries to sign in with out verifying their email I want Auth0 to resend the verification link and let the user know. For the most part I have gotten it working. My problem is the way I currently have it setup the action takes the user to the Callback page with the error message and a blank browser screen. After the action is done I want to redirect to another page that lets the user know what is going on. How do I redirect to such a page after the action is done. The following is my code for the Login Action and I am using a dependency auth0@2.35.0,
exports.onExecutePostLogin = async (event, api) => {
if (!event.user.email_verified) {
const ManagementClient = require(‘auth0’).ManagementClient;

const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.client_id,
clientSecret: event.secrets.client_secret,
});
var params = {
user_id: event.user.user_id
};

management.jobs.verifyEmail(params, function (err) {
if (err) {
console.log(err)
}
});
api.access.deny(‘Please verify your email before logging in.’);
}
};

You would need to build two pages, 1 which will handle error callbacks and 2 which you would show whenever you would like to ask the user to verify their email. Instead of denying access you can redirect the user to your custom verify your email page. The following link might be helpful:
https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/redirect-with-actions

1 Like