Fork me on GitHub
#reitit
<
2022-10-27
>
Benjamin13:10:53

what is the difference between the middleware I pass to {:data {:middleware in router and :middleware in ring-handler ? I use http://ring-clojure.github.io/ring/ring.middleware.resource.html and I want to make sure somehow that I also throw, if not authenticated with outh2-middleware

Benjamin13:10:41

(defn wrap-throw-auth [handler]
  (fn [req]
    (when (not (authenticated? req))
      (throw-unauthorized req)
      (handler req))))
tried this but I am not sure where I should put it.

ikitommi13:10:57

the middleware defined in router is applied only if a path is matched. the middleware in ring-handler wraps the whole app, so applies to path misses too.

dharrigan13:10:06

I use :middleware in the ring-handler to set a bunch of configuration (coming from donut system) on the request, so that these configuration options are available to every route. It's really nifty!