Catching error in /callback when user email not verified

I have used the UserEmailVerified action template to customise login so that it should check the user has verified their email address when logging in:

exports.onExecutePostLogin = async (event, api) => {
    if (!event.user.email_verified) {
        api.access.deny('Please verify your email before logging in.');

When testing with an unverified email address, the /callback page is returned showing an unhandled exception:

# An unhandled exception occurred while processing the request.

OpenIdConnectProtocolException: Message contains error: ‘access_denied’, error_description: ‘Please verify your email before logging in.’, error_uri: ‘error_uri is null’.

Unknown location

Exception: An error was encountered while handling the remote login.


How can I catch this error and redirect the user to a custom page that explains what they need to do? Project is core razor pages.

I cannot see, generally, how to catch errors thrown in /callback given this isn’t a page in my project I can edit.



Having spent more time trying this I think I have solved it.

I changed the Auth0 action to:

exports.onExecutePostLogin = async (event, api) => {
    if (!event.user.email_verified) {
        /**api.access.deny('Please verify your email before logging in.');*/

This lets me redirect sign ins from unverified emails to a custom page where I can explain what they need to do etc.

If there is a better way to handle this I’ll be glad to learn it :slight_smile: otherwise this is what I’m going with.