Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Forked from thheller/eliminate-nested-if.clj
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrtsa/878491ba0f6d97fe91f1 to your computer and use it in GitHub Desktop.
Save pyrtsa/878491ba0f6d97fe91f1 to your computer and use it in GitHub Desktop.
(defn get-user-from-request [request]
(when-let [ident (get-in request [:session ::friend/identity :current])]
(magic/user-by-id (get-in request [:myapp :system :db]) ident)))
(defn wrap-user
"Add user information to the request map if logged in."
[handler]
(fn [request]
(if-let [user (get-user-from-request request)]
(handler (assoc-in request [:myapp :user] user))
(handler request))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment