Fork me on GitHub
#fulcro
<
2021-07-30
>
caleb.macdonaldblack05:07:01

So i get an access token from Auth0 using .getTokenSilently(), This returns a promise. How can I get this token from within fulcro-http-remote request middleware so I can add it to my headers? I don’t want to store the token because Auth0 manages refreshing it with webworkers. If I store it i need to make a webworker to refresh it periodically which is what I’m trying to avoid.

stuartrexking05:07:38

A simpler solution might be to override the Xhrio object.

caleb.macdonaldblack05:07:04

(defn make-xhrio []
  (let [xhrio (XhrIo.)
        xhrio-send (.-send xhrio)]
    (o/oset! xhrio "send"
             (fn [url verb body headers]
               (auth-http/get-token-silently-callback app
                 (fn [token]
                   (let [headers (o/oset! headers :!Authorization token)]
                     (.apply xhrio-send xhrio (clj->js [url verb body headers])))))))
    xhrio))

stuartrexking05:07:13

Yeah like that.