Fork me on GitHub

I'm working on making a top navigation bar for my site built with Biff, and I want to display certain elements based on whether the user is logged in or not (including "Sign in" and "Sign out" buttons). Given that it's an element common to all pages, I initially thought it would make the most sense to load it into app/ui.clj, as an element called by ui/page that precedes the body, like so:

(def topbar
    [:a.text-blue-500.text-xl.font-semibold {:href "/"} "App Title"]
    [:a.text-blue-500 {:href "/genre"} "Genres"]
    [:a.text-blue-500 {:href "/user/followed"} "Followed"]
    [:a.text-blue-500 {:href "/app"} "Dashboard"]
    [:a.text-blue-500 {:href "/app/user/settings"} "Settings"]]

(defn page [opts & body]
However, ui/page has no access to the sys map that would allow me to check if the user is logged in or not. I have a couple of hacky ways that I could try to do this--maybe make another <feat>/page that wraps ui/page on each individual route, or change ui/page itself to accepts the sys map--but I'm not sure if either of these are considered "idiomatic" for Biff. Is there any ideal, idiomatic way to do this, or am I better off chasing one of the hackier solutions above?

Jacob O'Bryant01:12:20

I just pass the system map in! i.e. opts is the system map... which is possibly confusing. I've been thinking I should rename all occurrences of sys, req, or opts to ctx and have the docs refer to it as the context map.

🙌 1
Jacob O'Bryant01:12:40

I originally used the term opts in some places because you aren't necessarily passing in the system map and thus sys felt inappropriate. So ctx feels like a more general, clearer term. (Either that or maybe stuff, data, ...)


Ah, I see! That is very clean. Thanks for your help 👍


cloned a Biff project to a new machine and getting File does not exist: dev when running bb dev… thoughts?


bb.edn has

{:deps {local/deps {:local/root "tasks"}}
 :tasks {dev         com.biffweb.tasks/dev
         format      com.biffweb.tasks/format
         clean       com.biffweb.tasks/clean
         deploy      com.biffweb.tasks/deploy
         soft-deploy com.biffweb.tasks/soft-deploy
         refresh     com.biffweb.tasks/refresh
         restart     com.biffweb.tasks/restart
         logs        com.biffweb.tasks/logs
         prod-repl   com.biffweb.tasks/prod-repl
         prod-dev    com.biffweb.tasks/prod-dev
         hello       wiki.treeplanet.tasks/hello

         post-receive com.biffweb.tasks/post-receive
         run-cmd      com.biffweb.tasks/run-cmd}}
and the task directory is there.


what's your bb --version?


Haha! You’re onto it. Just after posting this I realized I had a very old version. I then attempted to update it with brew, but I had originally installed it on this machine with the curl script. I then reran the curl install script, and now I’m having a lot of fun as running, say, bb throws

Error: Could not find or load main class clojure.main
Caused by: java.lang.ClassNotFoundException: clojure.main
so working through that.


running bb outside the project directory works, but not inside of it. However, I’m glad to say that bb --version outside the project shows I now have Babashka v1.0.168 REPL.


(I don’t have an M1 MacBook as the OP of the issue did, fyi)


bb --version and bb work inside the Biff project directory if I rename bb.edn to something else.


On my phone right now but this sounds like an issue with your #CLX41ASCS installation. I don't use brew but I think that has caused some problems in the past?


I think you'll get a solution faster over at #CLX41ASCS


Oh you said it works outside the project, Ican check it out in half an hour or so


Aha! I removed ~/.deps.clj and that solved the issue. This is a directory created by babashka.

👍 1
👌 1

Thank you for all the help! 😀


Oh, the old version of babashka created deps.clj and confused the new one? That's interesting


I just saw a mention of deleting ~/deps.clj in that thread I linked to above and tried it. My situation is a bit unusual, though… I cloned a project down into a machine that had early versions of bb and so on. Truly a corner case and not a Biff thing, that’s for sure.

👍 1