Removed Top-Level Awaits

This commit is contained in:
Annika Merris 2024-02-29 23:02:58 -05:00
parent 6123437a07
commit 1ac38f584e
2 changed files with 59 additions and 54 deletions

View file

@ -23,18 +23,12 @@ const vuetify = createVuetify({
} }
}) })
const conf: Config = await getConfig().then((c: Config | null): Config => { getConfig().then((conf: Config | null) => {
if (c === null) { configureOidc().then((authentikAuth) => {
throw new Error("config was null") if (conf === null) {
throw new Error('config was null')
} }
return c authentikAuth.startup().then((ok: boolean) => {
}).catch((reason) => {
console.log(reason)
throw new Error(reason);
})
const authentikAuth = await configureOidc()
authentikAuth.startup().then((ok: boolean) => {
if (ok) { if (ok) {
const app = createApp(App) const app = createApp(App)
const pinia = createPinia() const pinia = createPinia()
@ -49,4 +43,10 @@ authentikAuth.startup().then((ok: boolean) => {
app.mount('#app') app.mount('#app')
} }
})
})
})
.catch((reason) => {
console.log(reason)
throw new Error(reason)
}) })

View file

@ -4,8 +4,13 @@ import type { Config } from '@/types/Config'
import type { OidcAuth } from 'vue-oidc-client/vue3' import type { OidcAuth } from 'vue-oidc-client/vue3'
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
const oidcAuth: OidcAuth = await configureOidc().then((value: OidcAuth): OidcAuth => value) let config: Config = {} as Config
const config: Config = await getConfig().then((value: Config | null): Config => value !== null ? value : {} 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({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
@ -29,30 +34,30 @@ const router = createRouter({
path: '/intimacy-power', path: '/intimacy-power',
name: 'intimacy-power', name: 'intimacy-power',
component: () => import('@/views/IntimacyPowerView.vue') 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) { if (config.oidcProjectID === undefined) {
throw new Error('Config was not loaded') throw new Error('Config was not loaded')
} }
const roles = oidcAuth.userProfile[`urn:zitadel:iam:org:project:${config.oidcProjectID}:roles`] as Array<any> const roles = oidcAuth.userProfile[
`urn:zitadel:iam:org:project:${config.oidcProjectID}:roles`
] as Array<any>
if (!roles) { if (!roles) {
return false return false
} }
return roles.find(r => r[role]) return roles.find((r) => r[role])
} }
oidcAuth!.useRouter(router)
export default router export default router