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.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()
How can I catch this error and redirect the user to a custom page that explains what they need to do? Project is ASP.net 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.
Thanks
Stuart