This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-18
Channels
- # aws (1)
- # babashka (35)
- # beginners (52)
- # biff (4)
- # calva (55)
- # cider (19)
- # clojure (54)
- # clojure-dev (3)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (2)
- # clojurescript (9)
- # code-reviews (3)
- # datahike (1)
- # fulcro (1)
- # funcool (4)
- # graalvm (21)
- # gratitude (2)
- # java (5)
- # jobs (2)
- # joyride (1)
- # kaocha (13)
- # malli (2)
- # off-topic (22)
- # other-languages (11)
- # pathom (4)
- # re-frame (35)
- # reagent (3)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (42)
- # sql (18)
- # tools-deps (72)
- # web-security (6)
- # xtdb (15)
Yay! Just finished the tutorial so far! So awesome, and it all worked perfectly. I learned mainly about middleware… I had db calls all over my code before this. :star-struck:🙌😎
Currently trying to build an application that has a “guest-facing” side (i.e. available to unauthenticated users), but I want the guest-facing side to display some extra elements if the user is authenticated. I suspect this involves middleware—the best I can come up with is a wrap-maybe-signed-in
that adds the :uid
key if auth’d, but allows proceeding to the desired page regardless of result.
I’ve been poking through Platypub and the Biff source code itself, but can’t quite see how to accomplish this. Is middleware my best way forward? If so, what would that approximately look like?
> I suspect this involves middleware—the best I can come up with is a wrap-maybe-signed-in
that adds the :uid
key if auth’d, but allows proceeding to the desired page regardless of result.
This is basically in place already: make sure the public routes aren't wrapped with wrap-signed-in
, then in the handlers, look at (some? (-> req :session :uid))
to determine if the user is signed in or not. If you want to load the user document on each request, then a wrap-maybe-signed-in
would work well. I might call it wrap-user
:
(defn wrap-user [handler]
(fn [{:keys [biff/db] {:keys [uid]} :session :as req}]
(handler (cond-> req
(some? uid) (assoc :user (xt/entity db uid))))))