I would like to store some information about a logged in user in the session. I tried doing it via a middleware, but every time I visit a new page/route, the middleware that collects user info runs again because the info from the previous session is gone. Do I need to explicitly assoc response :session session in all of my routes to keep these values around from page to page?
(defn wrap-user-info
[handler]
(fn [request]
(if (contains? (:session request) :okta-user-info)
(handler request)
(let [okta-user-info-res (okta-user-info request)]
(info "Adding user info to session")
(handler (-> request
(assoc-in [:session :okta-user-info] okta-user-info-res)))))))If you have middleware in your stack to handle sessions, it should "just work" I think.
I do recall running into some issues at one point because I had middleware in the wrong order and sessions were being lost if my handler used response to generate the result. That's why ring-defaults is such a useful library: it makes sure you have (almost) everything in place in the right order.