noir-clojure / lib-noir

A set of libraries for ring apps, including stateful sessions.
Eclipse Public License 1.0
481 stars 47 forks source link

Flash session storage apparently not working in lib-noir. #22

Closed r0adrunner closed 11 years ago

r0adrunner commented 11 years ago

BUG DESCRIPTION: Flash session storage apparently not working in lib-noir.

STEPS TO REPRODUCE:

1) For practical reasons, I'm using the scaffolding tool provided by the luminus framework:

lein new luminus guestbook

2) Change the following in the file 'handler.clj': Add:

(:use [noir.session :only [wrap-noir-flash*]])

Comment out:

(def app (middleware/app-handler all-routes))

Add:

(def app
  (-> (middleware/app-handler all-routes)
      (wrap-noir-flash*)))

3) Change the following in the file 'routes/home.clj':

Add these dependencies:

(:use [noir.session :only [flash-put! flash-get]])

Add these routes to the home-routes:

(GET "/step1" [] (route1))
(GET "/step2" [] (route2))

Add these functions:

(defn route1 []
  (flash-put! :var1 "something")
  (layout/common
   "this sets in a flash session variable."))

(defn route2 []
  (layout/common
   (str "this retrieves the flash var: " (flash-get :var1 "nothing"))))

4) Make sure changes are in effect and navigate to "http://localhost:3000/step1" and then to "http://localhost:3000/step2"

EXPECTED RESULT: "http://localhost:3000/step2" prints the word "something"

ACTUAL RESULT: "http://localhost:3000/step2" prints the word "nothing"

yogthos commented 11 years ago

The problem was caused by wrap-noir-session wrapping the request before wrap-noir-flash is used. Updated the app-handler to include them in the correct order which resolves the issue.

@r0adrunner could you retest with the latest lib-noir 0.3.7 and see if the problem is resolved. I tested locally and seems to be working as expected. I updated the app-handler to include the wrap-noir-flash, so that you don't have to do that explicitly now:

(def app (middleware/app-handler all-routes))