This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-18
Channels
- # announcements (3)
- # babashka (13)
- # beginners (28)
- # biff (12)
- # clj-yaml (13)
- # clojure (13)
- # clojure-europe (2)
- # clojure-norway (11)
- # clr (1)
- # core-typed (3)
- # datahike (1)
- # datascript (5)
- # datomic (12)
- # fulcro (8)
- # graalvm (8)
- # hyperfiddle (20)
- # missionary (8)
- # off-topic (20)
- # pedestal (1)
- # releases (2)
- # shadow-cljs (12)
- # yamlscript (7)
I'm further along in the tutorial now and I believe I've found a bug: localhost:8080/app
does not really redirect like it should if you're not logged in. The crux of the issue (at least based on my testing^) is that u get {}
when no user is found. But {}
is truthy.
(^ I havent dug into XTDB yet. Btw, the link for https://docs.xtdb.com/language-reference/datalog-queries/#pull at https://biffweb.com/docs/tutorial/communities/ is now giving me a 404?)
This is the original tutorial code:
(defn wrap-signed-in [handler]
(fn [{:keys [biff/db session] :as ctx}]
(if-some [user (xt/pull db
'[* {(:membership/_user {:as :user/memberships})
[* {:membership/community [*]}]}]
(:uid session))]
(handler (assoc ctx :user user))
{:status 303
:headers {"location" "/?error=not-signed-in"}})))
And this is the code I've been going with to correct the issue (with prn
s in there really just so I can see; they can be removed):
(defn wrap-signed-in [handler]
(fn [{:keys [biff/db session] :as ctx}]
(println "before wrapping: (:uid session), session =")
(prn (:uid session))
(prn session)
(let [user (xt/pull db
'[* {(:membership/_user {:as :user/memberships})
[* {:membership/community [*]}]}]
(:uid session))]
(if (empty? user)
{:status 303
:headers {"location" "/?error=not-signed-in"}}
(handler (assoc ctx :user user))))))
ah, thanks for the catch--will update both those soon. I wonder if it's always been like that or if xt/pull
chanced at some point.
π no idea on that one. But yeah, that could very well have been the case. Either way, this is a fix for the situation now.
the choice of empty?
came intuitively to me, btw (I am used to ruby). If you think that there is a better choice than empty?
for doing the test, pls let me know
question about the schema for :message
(https://biffweb.com/docs/tutorial/communities/): is there a reason why :message has :message/membership :membership/id]
, as opposed to :message/user :user/id
? if the argument is that the membership ties the message back to not just the user, but the community as well through membership (because membership has :membership/user
, and :membership/community
), one could also :message/channel
would take care of the tie to the community
It could work either way--I don't think I had a super strong reason to link to the membership instead of the user. I might've been thinking that a user might want to have a different display name etc for different communities, which would presumably be stored on the membership, in which case you might be dealing with memberships more than users. I'm sure there'd be advantages of doing it the other way though.
gotcha. Thank you for responding! would you happen to have a recommended resource for learning more about XTDB? no datomic experience here if that matters
of course!
for XTDB, the docs are really good: https://v1-docs.xtdb.com/main/ (if you go to http://XTDB.com you have to be sure to navigate to the docs for v1, since v2 is shown primarily). I've spent a lot of time going over the transaction and query references: https://v1-docs.xtdb.com/language-reference/datalog-transactions/ , https://v1-docs.xtdb.com/language-reference/datalog-queries/. I also highly recommend playing around with in-memory nodes in the repl, E.g. you can do (with-open [node (xt/node {})] ...)
and then do whatever--call submit-tx + await-tx, query for the documents you just submitted, etc. I did that a lot for learning XTDB v2 just recently, especially since the docs for v2 aren't quite as polished yet as the ones for v1.
thank you! re v2, do you think itβs better to start learning with v2? or stick with v1 for now?
I'd recommend v1 for now since v2 is still experimental and missing some useful features that v1 has. and of course Biff is still on v1 by default π