How to make session data in http-kit

211 Views Asked by At

For my login system, I need to implement session data for different functionality when users are logged in or not.

I've only ever done sessions in flask, and google searches don't reveal a lot (or, more likely, I'm searching the wrong things). I have two questions:

  1. Is there a canonical way to do session data in Clojure and can this specifically done in http-kit?
  2. Is an atom enough, or would this be bad practice?
1

There are 1 best solutions below

0
kopos On

sessions will have to be managed via ring. http-kit is a server & will only use the ring spec for requests and responses.

To fetch the session

(get-in req [:session :auth-token])

To add a session to your ring response

(assoc res
       :session {:auth-token auth-token
                 :userid (:id json-data)
                 :username (:username json-data)})