This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-07-19
Channels
- # announcements (5)
- # beginners (36)
- # calva (2)
- # cider (26)
- # cljs-dev (2)
- # clojure (121)
- # clojure-spec (2)
- # clojure-uk (2)
- # clojurescript (12)
- # component (1)
- # conjure (6)
- # datomic (9)
- # docker (1)
- # fulcro (15)
- # lambdaisland (1)
- # malli (5)
- # meander (24)
- # off-topic (5)
- # re-frame (5)
- # reagent (3)
- # ring (3)
- # shadow-cljs (41)
- # sql (4)
- # vim (3)
- # xtdb (7)
I'm storing an auth token in the app db that I need to add to the request headers in my remote. I think the right place to do this is in request middleware, but I don't have access to the app-db from there. Using cookies isn't an option. Maybe I should provide the app db atom to my fulcro application and then access it directly?
or just def an atom to hold the token ... :man-shrugging:
This is why the book tells you to def your app: (defonce SPA (fulcro-app …))
Now you have access to state anywhere with (app/current-state SPA)
Ah, but you have a circular ref problem if you’re doing middleware, since your middleware would need the app, but app needs your remote, which in turn needs the middleware 😜
I ended up just closing over the app itself in the request middleware function (declared app, first).
(declare app)
(defn access-token []
(-> app ::app/state-atom deref :pawlytics/access-token))
(defn auth-middleware
[request]
(let [access-token (access-token)]
(cond-> request
access-token
(assoc-in
[:headers "Authorization"]
(str "Bearer " access-token)))))
(defonce app
(app/fulcro-app
{:remotes
{:remote (http-remote/fulcro-http-remote
{:url "/api/admin"
:request-middleware (http-remote/wrap-fulcro-request
auth-middleware)})}}))
Hello, running the fulcro template, under the main app, I'm getting a blank page with "Not found. Missing index.html."
same issue.
the main app requires the server to be running (and serving) - i assume you've started it and that is the httpd you are hitting when you browse? (you should see it logging like this:
20-07-19 22:30:11 surface-system DEBUG [app.server-components.middleware:38] - Serving index.html
)@U017JCS7L2Y I am running (shadow/repl :main)
, as said in the docs
that is the front end - clojurescript component. you also need the api server (or workspaces) in order to load the spa. the docs describe this too