;; Define an interceptor
(def require-admin
{:name :require-admin
:enter (fn [ctx]
(if (admin? (get-in ctx [:request :session :user]))
ctx
(assoc ctx :response {:status 403 :body {:error "Forbidden"}})))
:leave (fn [ctx] ctx) ; optional response processing
:error (fn [ctx err] ; optional error handling
(assoc ctx :response {:status 500 :body {:error "Internal error"}}))})
;; Attach interceptors to routes
[{:path "/api/admin"
:methods {:post {:handler 'handlers/create-resource
:interceptors ['auth/require-admin
'audit/log-action]
:summary "Create admin resource"}}}]