Fork me on GitHub
#re-frame
<
2021-11-17
>
ns08:11:49

Prior to initializing my app and pulling any actual app data, I have to do a get request to get authorization token which I will then send with every api request - my question is, how do I make my app "wait" until this token request is done prior to initializing and dispatching any other requests? My app is done with re-frame. Any help is appreciated!

p-himik08:11:37

You have some event somewhere that initializes the whole app-db and kicks off the app. You can dispatch that event not on the render but on the auth token reception.

Wilson Velez12:11:16

I’m using async flow https://github.com/day8/re-frame-async-flow-fx for something similar, maybe it helps

emccue15:11:08

Don’t use async flow for this. The least horrible solution I have found is to use promesa at app bootup to make your initial app-db

(p/let [auth-response (... make request to get token ...)]
  (let [initial-db {:auth-token (... auth-response ...)}]
    (rf/dispatch-sync [:init initial-db])))

javi15:11:46

i use the same approach as emccue.

ns16:11:29

Thank you everyone.