[coldbox-5.6.2] Prehandler not preventing handler from executing when auth fails

Hi,
I’m using a prehandler in my API call similar to the one in the example here:
https://coldbox.ortusbooks.com/digging-deeper/recipes/building-rest-apis

My API is set up the same way as the examples in the link above.

The prehandler does not prevent the index handler from executing despite failing user auth.

[my code removed but confirmed working]
<cfif ! FALSE>
<cfset event.renderData( type=“json”, data={data}, statusCode=403, statusMessage=“not authorized”) />

[my stuff}
<cfset event.renderData( type=“json”, data=local.response, statusCode=local.response[“statuscode”], statusMessage=local.response[“message”]) />

How can the prehandler stop the index method from firing?

I tried adding event.noExecution() after renderData in the preHandler but it still executes the preHandler and the index event resulting in the index renderData being shown.

When I comment out the index renderData the preHandler renderData is shown so it’s running just not stopping the event from continuing to the index event.

I’m still not sure how to stop the index event from happening in the preHandler.

Gave up on the prehander and used a preProcess interceptor instead.

Hi Jen

If authentication failed then in preHandler you can override the event (redirect to another handler or method )

Yes, override to another event worked but that’s not what I wanted. I wanted the renderData function to execute to return the failure reason and then stop the event from processing.

I ended up using an interceptor preProcess function and it works as I intended it to.

Thank you for responding, Sana.