    [clojure.pprint :refer (pprint)]
    [clojure.set :as set]
    [bidi.bidi :as bidi :refer (path-for resolve-handler unresolve-handler ->WrapMiddleware Matched)]
-   [modular.ring :refer (RingHandlerProvider)]
-   [modular.index :refer (Index)]
+   [modular.ring :refer (handler RingHandlerProvider)]
    [modular.bidi :as modbidi :refer (BidiRoutesProvider routes context)]
    [schema.core :as s]
    [ring.middleware.cookies :refer (wrap-cookies cookies-request)]


;; Authorization

;; Bidi handlers can be subject to access restrictions. We restrict at
;; the level of the handler rather than the route, because it's the
;; handler that determines what kind of data is being returned. It is

that authentication fails."
  ([h authenticator failure-handler]
     (fn [req]
       (let [auth (allowed-request? authenticator req)]
         (cond auth (h (merge req auth))
               failure-handler (failed-authentication failure-handler req)
               ;; Continue without merging auth
               :otherwise (h req)))))
  ([h authenticator]
     (wrap-authentication h authenticator nil)))

