Fork me on GitHub

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)


You can also use an atom


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 😜


ah, dynamic langs


yeah, I’d just use my own atom probably


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
  (let [access-token (access-token)]
    (cond-> request
              [:headers "Authorization"]
              (str "Bearer " access-token)))))
(defonce app
           {:remote (http-remote/fulcro-http-remote
                      {:url "/api/admin"
                       :request-middleware (http-remote/wrap-fulcro-request

Quentin Le Guennec08:07:40

Hello, running the fulcro template, under the main app, I'm getting a blank page with "Not found. Missing index.html."


did you navigate to /index.html?

jb recluse22:07:01

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

Quentin Le Guennec07:07:51

@U017JCS7L2Y I am running (shadow/repl :main) , as said in the docs

jb recluse13:07:34

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