mxcd
mxcd

Reputation: 2404

Awaiting code execution in quasar.dev boot file before vue.js instantiation

The quasar.dev framework introduces the concept of boot files: https://quasar.dev/quasar-cli/boot-files
Using the vue-oidc-client, I am required to wait for the oidc.startup() call before the Vue instance is created (see https://github.com/soukoku/vue-oidc-client/wiki#app-start)

Since I can't simply put an await outside of an async function, I am wondering how I can achieve this.

My code as reference:

// Importing stuff and creating 'oidc' with createOidcAuth(...)

const startupSucessful = oidc.startup()
if(!startupSucessful) throw Error("Unable to bootstrap OIDC client");

export default boot(async ({ app, router, Vue }) => {
  oidc.useRouter(router);
});

Upvotes: 1

Views: 1222

Answers (1)

wipallen
wipallen

Reputation: 154

Since your export block is async, just put the code you want to wait for there:

export default async ({ app, router, Vue }) => {
  
  const startupSucessful = await oidc.startup()
  
  if(!startupSucessful) 
    throw Error("Unable to bootstrap OIDC client");
  else
    oidc.useRouter(router);
  
});

Upvotes: 1

Related Questions