843606775c
* 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
29 lines
836 B
TypeScript
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
|
|
})
|