I have two sets of compojure routes, public ones, which need no authentication, and private ones which need authentication.
(defroutes public-routes
(GET "/" [] homepage-handler))
(defroutes private-routes
(GET "/secrets" [] secrets-handler))
I created a middleware which checks is the user authenticated and either continues the middleware chain or raises.
(defn wrap-must-be-authenticated [handler]
(fn [request]
(if (authenticated? request)
(handler request)
(throw-unauthorized))))
(def app
(-> private-routes
(wrap-must-be-authenticated)))
This works fine, all "private routes" require authentication.
How would I go about adding the public-routes
so they are excluded from wrap-must-be-authenticated
?
I believe defroutes
returns ring handlers, so I'm thinking I need to do something like:
(-> (wrap-must-be-authenticated private-routes)
public-routes)