import { MeDocument } from '~/composables/graphql/generated';
import { hasManagerAccess } from '~/utils/roles';

export default defineNuxtRouteMiddleware(async () => {
  const { client } = useApolloClient('default');
  const response = await client.query({
    query: MeDocument,
    fetchPolicy: 'cache-first',
  });

  if (!hasManagerAccess(response.data.me?.role)) {
    return navigateTo('/');
  }
});
