mirror of
https://forgejo.merr.is/annika/isl-vue3.git
synced 2025-12-11 10:56:31 -05:00
Removed Top-Level Awaits
This commit is contained in:
parent
6123437a07
commit
1ac38f584e
2 changed files with 59 additions and 54 deletions
50
src/main.ts
50
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)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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<any>
|
||||
const roles = oidcAuth.userProfile[
|
||||
`urn:zitadel:iam:org:project:${config.oidcProjectID}:roles`
|
||||
] as Array<any>
|
||||
if (!roles) {
|
||||
return false
|
||||
}
|
||||
return roles.find(r => r[role])
|
||||
return roles.find((r) => r[role])
|
||||
}
|
||||
|
||||
oidcAuth!.useRouter(router)
|
||||
|
||||
export default router
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue