Files
speckle-server/packages/frontend-2/middleware/canViewWebhooks.ts
T
andrewwallacespeckle 69decafb5d feat(fe2): Hide settings tab for logged out users (#2261)
* Hide settings for logged out users

* Hide settings tab for non-logged in users

* Add middleware to settings to login

* Add middleware

* Update to webhooks middleware

* Updates to middleware

* Changes to middleware

* Update comments
2024-05-16 12:55:53 +02:00

31 lines
1.0 KiB
TypeScript

import { Roles } from '@speckle/shared'
import { useApolloClientFromNuxt } from '~~/lib/common/composables/graphql'
import { convertThrowIntoFetchResult } from '~~/lib/common/helpers/graphql'
import { projectSettingsRoute } from '~~/lib/common/helpers/route'
import { projectRoleCheckQuery } from '~~/lib/projects/graphql/queries'
/**
* Apply this to a page to prevent unauthenticated access to webhooks and ensure the user is the owner
*/
export default defineNuxtRouteMiddleware(async (to) => {
const client = useApolloClientFromNuxt()
// Fetch project role data to check if the user is the owner
const projectId = to.params.id as string
const { data } = await client
.query({
query: projectRoleCheckQuery,
variables: { id: projectId }
})
.catch(convertThrowIntoFetchResult)
// Check if the user is the owner of the project
const isOwner = data?.project.role === Roles.Stream.Owner
if (!isOwner) {
return navigateTo(projectSettingsRoute(projectId))
}
return undefined
})