Files
speckle-server/packages/frontend-2/middleware/admin.ts
T
Kristaps Fabians Geikins 843606775c feat(fe2): parallel middlewares (#5314)
* parallel middlewares foundation + hydration mismatch

* moved to fully parallel middlewares

* a bit less hacky

* some more cleanup

* improved nuxt 4 error formatting

* make parallel middlewares toggleable
2025-08-27 12:38:04 +03:00

29 lines
836 B
TypeScript

import { activeUserQuery } from '~~/lib/auth/composables/activeUser'
import { useApolloClientFromNuxt } from '~~/lib/common/composables/graphql'
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql'
import { Roles } from '@speckle/shared'
/**
* Apply this to a page to prevent access by non-admin users
*/
export default defineParallelizedNuxtRouteMiddleware(async () => {
const client = useApolloClientFromNuxt()
const { data } = await client
.query({
query: activeUserQuery
})
.catch(convertThrowIntoFetchResult)
// If user is not an Admin, show 403 message.
if (data?.activeUser?.role !== Roles.Server.Admin) {
return abortNavigation(
createError({
statusCode: 403,
message: 'You do not have access to this page'
})
)
}
return undefined
})