diff --git a/src/main.ts b/src/main.ts index 0477afc..3706028 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,30 +23,30 @@ const vuetify = createVuetify({ } }) -const conf: Config = await getConfig().then((c: Config | null): Config => { - if (c === null) { - throw new Error("config was null") - } - return c -}).catch((reason) => { +getConfig().then((conf: Config | null) => { + configureOidc().then((authentikAuth) => { + if (conf === null) { + throw new Error('config was null') + } + authentikAuth.startup().then((ok: boolean) => { + if (ok) { + const app = createApp(App) + const pinia = createPinia() + + app.use(router) + app.use(vuetify) + app.use(pinia) + + app.provide(oidc, authentikAuth) + + app.provide(apiBaseURL, conf.apiBaseURL) + + app.mount('#app') + } + }) + }) +}) +.catch((reason) => { console.log(reason) - throw new Error(reason); -}) - -const authentikAuth = await configureOidc() -authentikAuth.startup().then((ok: boolean) => { - if (ok) { - const app = createApp(App) - const pinia = createPinia() - - app.use(router) - app.use(vuetify) - app.use(pinia) - - app.provide(oidc, authentikAuth) - - app.provide(apiBaseURL, conf.apiBaseURL) - - app.mount('#app') - } + throw new Error(reason) }) diff --git a/src/router/index.ts b/src/router/index.ts index 5cb810a..0836a91 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -4,8 +4,13 @@ import type { Config } from '@/types/Config' import type { OidcAuth } from 'vue-oidc-client/vue3' import { createRouter, createWebHistory } from 'vue-router' -const oidcAuth: OidcAuth = await configureOidc().then((value: OidcAuth): OidcAuth => value) -const config: Config = await getConfig().then((value: Config | null): Config => value !== null ? value : {} as Config) +let config: Config = {} as Config +getConfig().then((conf: Config | null): Config => (config = conf !== null ? conf : ({} as Config))) +let oidcAuth: OidcAuth = {} as OidcAuth +configureOidc().then((auth: OidcAuth) => { + oidcAuth = auth + oidcAuth!.useRouter(router) +}) const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -29,30 +34,30 @@ const router = createRouter({ path: '/intimacy-power', name: 'intimacy-power', component: () => import('@/views/IntimacyPowerView.vue') - }, - { - path: '/test', - name: 'test', - component: () => import('@/views/TestView.vue') - }, - - { - path: '/login', - name: 'login', - meta: { - authName: oidcAuth.authName - }, - component: () => import('@/views/LoginView.vue') - }, - { - path: '/admin', - name: 'admin', - meta: { - authName: oidcAuth.authName - }, - component: () => - hasRole('admin') ? import('@/views/Admin.vue') : import('@/views/NoAccess.vue') } + // { + // path: '/test', + // name: 'test', + // component: () => import('@/views/TestView.vue') + // }, + + // { + // path: '/login', + // name: 'login', + // meta: { + // authName: oidcAuth.authName + // }, + // component: () => import('@/views/LoginView.vue') + // }, + // { + // path: '/admin', + // name: 'admin', + // meta: { + // authName: oidcAuth.authName + // }, + // component: () => + // hasRole('admin') ? import('@/views/Admin.vue') : import('@/views/NoAccess.vue') + // } ] }) @@ -60,13 +65,13 @@ const hasRole = (role: string) => { if (config.oidcProjectID === undefined) { throw new Error('Config was not loaded') } - const roles = oidcAuth.userProfile[`urn:zitadel:iam:org:project:${config.oidcProjectID}:roles`] as Array + const roles = oidcAuth.userProfile[ + `urn:zitadel:iam:org:project:${config.oidcProjectID}:roles` + ] as Array if (!roles) { return false } - return roles.find(r => r[role]) + return roles.find((r) => r[role]) } -oidcAuth!.useRouter(router) - export default router