Auth0 Home Blog Docs

API responding to a rule

auth0
rules
redirect-rules

#1

I’ve been following this guide: https://auth0.com/docs/rules/current/redirect to use rules so that I can register a user’s user_Id as a foreign key to related records. In my rule, I’m checking to ensure the protocol is not a redirect callback and that this is the user’s first time logging in (registering). That worked great, however I’m not exactly sure how to handle any errors down the Rule pipeline.

For example when creating a user, I check the database connection and if it’s unavailable then an error is thrown, if the new user record cannot be made, then another error is thrown, or what if the user.user_id or state from the Rule somehow doesn’t get passed as query arguments to my API?

Currently I’ve been catching those errors, and if found then I redirect the user to a custom “Unauthorized” url. This seems a little bit hacky, and I’m wondering if there is any functionality in Auth0 that handles these errors more elegantly, such as on an error, redirecting to some particular Auth0 route (maybe even Lock again).

FYI, using React front-end and Go for the API.

Any help is appreciated!