Following a previous question where I asked on how on earth do sessions work in Clojure, I have been experimenting with Monger.
In the documentation, you can find the code snippet:
(ns monger.docs.examples
(:require [monger.core :as mg]
[monger.ring.session-store :refer [monger-store]]))
;; create a new store, typically passed to server handlers
;; with libraries like Compojure
(let [conn (mg/connect)
db (mg/get-db conn "monger-test")]
(monger-store db "sessions"))
which is helpful, but I don't know how to implement the handler. Is there anyone who explain how this would work interacting with a handler, or being embedded in a handler itself?
EDIT:
So far I've tried:
(def app-handler
(let [{:keys [_ db]} (mg/connect-via-uri (env :mongo-uri))]
(-> handler
(session/wrap-session {:store (session-store db "sessions")}))))
but get:
java.lang.ClassCastException: class java.lang.String cannot be cast to class clojure.lang.Associative (java.lang.String is in module java.base of loader 'bootstrap'; clojure.lang.Associative is in unnamed module of loader 'app')
So, it obviously doesn't like the mapping in-front, but this is the pattern I've seen everywhere else. Any ideas are (and explanations) would be wonderful!
What is
handler? Can you add a bit more code of what you tried?According to the error message somewhere you return a string, where a map is expected.
Note that
session-storeshould return an implementation ofring.middleware.session.store/SessionStore. Seewrap-session.