lock not displaying custom rule error

I’m using NodeJS and Lock version 10.16

I have implemented the Force Email Verification rule and I’m trying to display the error on lock. I am using the code recommended for this according to the docs:

lock.on("authorization_error", function(error) {
     
      lock.show({
        loginAfterSignUp: false,
        flashMessage:{
          type: 'error',
          text: error.error_description
        }
      });

However, when testing this on my web app, lock does not open and display the error after the failed login attempt, instead it reloads my page with

/?error=unauthorized&error_description=Please%20verify%20your%20email%20before%20logging%20in.

appended at the end. Interestingly, if I manually change the ? to a # lock will open and display the error. Does anyone have any idea what is going on here?

You did not provide your Lock initialization options and how you show it so it’s not possible to provide a definitive answer.

Based on the information provided you’re using an authorization code grant (response type code) which means the authentication response is delivered as part of the query string of the provided redirect URL. This is meant to enable the response to be processed by the server-side component processing your redirect URL.

The Lock events are triggered when the authentication response is delivered as part of the fragment component of the redirect URL as this is meant for the cases where the response should be directly processed by Javascript components.

If you want to process the response on the server-side then you need to respond with logic that shows the error if applicable without relying on the Lock client-side events.

If you are okay with processing the response client-side you probably need to change your response type to token id_token.

Thanks for getting back to me. My responseType was set to code, and setting it to token worked. I appreciate your help so much as I spent a really long time trying to figure this out!!! Thank you!

Thanks for getting back to me. My responseType was set to code, and setting it to token worked. I appreciate your help so much as I spent a really long time trying to figure this out!!! Thank you!