Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

How to wait for api call on js export?

$
0
0

I have a Vue app where I initialize my firestore app. My code looks like the following:

if (firebase.apps.length) {
  firebase.app()
} else {
  firebase.initializeApp(config)
}
export const Firestore = firebase.firestore()
export const Auth = firebase.auth()

Now I would like to bring the config file from some API. Which mean, instead of doing firebase.initializeApp(config) I would like to do something like:

axios.get('https://.../config.json', {})
    .then(async ({ data }) => {
      firebase.initializeApp(data)
    })
    .catch((err) => {
      console.log('error', err)
    })

But my exports will have to wait till I get the response from the API and init the app.

How can I make the exports wait with async/await or any other pattern?


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>