mirror of
https://forgejo.merr.is/annika/isl-vue3.git
synced 2025-12-13 15:04:41 -05:00
Removed Top-Level Awaits
This commit is contained in:
parent
6123437a07
commit
1ac38f584e
2 changed files with 59 additions and 54 deletions
20
src/main.ts
20
src/main.ts
|
|
@ -23,17 +23,11 @@ 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
|
|
||||||
}).catch((reason) => {
|
|
||||||
console.log(reason)
|
|
||||||
throw new Error(reason);
|
|
||||||
})
|
|
||||||
|
|
||||||
const authentikAuth = await configureOidc()
|
|
||||||
authentikAuth.startup().then((ok: boolean) => {
|
authentikAuth.startup().then((ok: boolean) => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
@ -50,3 +44,9 @@ authentikAuth.startup().then((ok: boolean) => {
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((reason) => {
|
||||||
|
console.log(reason)
|
||||||
|
throw new Error(reason)
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue