How to take specific action when authorization is denied in a Pre User Registration Auth0 custom Action

I’m using Auth0 Lock for logins/registrations and I’ve implemented a Pre User Registration custom Action to perform additional verification on users before allowing access. Everything is working fine, and I’m passing a “reason” and a “message” to the call to api.access.deny(), which can be different depending on which problems are detected in the Action. I can see the “reasons” displayed in the Auth0 monitoring log.

I would like to take different actions on our end, such as redirecting to specific pages, depending on the “reason” a user has been denied access. However, I haven’t found a way to access the “reason” after the access denial occurs.

I’ve tried listening for lock->authorization_error and lock->unrecoverable_error but neither appear to be triggered. So far, the only way that I’ve found to even know that the access denial has occurred is because the lock.fallback error is displayed. So I could modify the error message to handle this case, but obviously this is far from ideal.

So, how can I find out the “reason” a user has been denied access from a Pre User Registration custom Action?

Hi @stephenrs,

Welcome to the Auth0 Community!

Yes, this happens because the api.access.deny() method stops the sign up process immediately and prevents any further actions from being executed. (Reference: Actions Triggers: pre-user-registration - API Object)

It’s also important to note that a pre-user registration action will not allow you to redirect users to external pages. Only a post-login action can redirect users.

If you need to redirect your users based on certain conditions after they sign up, you should use a post-login action instead.

You can find out the reason a user has been denied access by checking your logs.

Let me know if you have any questions.

Thanks,
Rueben

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