Custom error in rules in Auth0 - HOW TO

Hello team,
I have been through all discussion threads on that topic and could not find a good answer on how to handle that.
I created rules in Auth0 to perform advanced filtering/checks and want to raise errors in case something goes wrong.
Simple example: make sure people confirmed their email before logging in.
When the user tries to login before confirming his/her email, I want him/her to get an error message inviting him/her to confirm the email in the first place.

I am using the default template for the rule and creating a custom error:

function (user, context, callback) {
if (!user.email_verified) {
return callback(new UnauthorizedError(‘lock.email_not_verified’));
} else {
return callback(null, user, context);
}
}

I am using the Universal Login.
I have added the error definition in the LanguageDictionnary as per the documentation https://auth0.com/docs/libraries/lock/v11/customizing-error-messages

I tried with FlashMessages but could not get it work.

Is there a proper how-to guide that cover that topic in details?
Thanks in advance!
Romain

1 Like

Hey there @rjourdan_net, I wanted to follow up and find out if this solution would work for your situation that dives into crafting a custom error page. Please let me know if you have any questions or if this helps you in your pursuit. Thanks!

If you configure a redirection for the error page then the configured URL should receive the information about the error event through query parameters. In particular, the information you mentioned should be available in error and error_description parameters if I recall correctly.
Details of error when redirecting to custom error page

Hi @rjourdan_net, following up to see if you had any additional questions on this front. Please let me know if I can be of further assistance to you, thanks!

I’m gonna latch onto this one, as I’m facing the same issue.

@James.Morrison The custom error page doesn’t quite solve it, as errors thrown by a rule always result in a redirect to the application /callback, but with error and error_message query strings, right? What @rjourdan_net seems to be asking is for a custom error page to be shown if a rule throws an error.

How I’ve solved it in my tenant for now, is to not throw an actual error in a rule, but to do a redirect to an external error page. That means none of the errors show up in my Auth0 log, though, so that’s a pretty significant trade-off.

1 Like

At the moment this type of use case isn’t currently support. However it’s important to be aware of that every authentication flow will end up with a /callback. I would recommend sharing your use case and feedback at Auth0: Secure access for everyone. But not just anyone. so we can consider how to proceed forward with these types of requests. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.