0

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!

Jack Gee
  • 136
  • 6
  • Seems like your main issue is building a web server. Check out https://github.com/dharrigan/startrek for a simple but complete example of one. Even though it uses a particular web server (`juxt/clip`), it should at least give you an understanding of how separate parts should work together. – Eugene Pakhomov Oct 13 '22 at 07:37

1 Answers1

0

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-store should return an implementation of ring.middleware.session.store/SessionStore. See wrap-session.

user2609980
  • 10,264
  • 15
  • 74
  • 143