refactor(hunt): replace admin middleware with auth and implement membership state

- Change middleware from 'admin' to 'auth' on hunt and quest admin pages
- Add global hunt store to track current hunt ID and membership status
- Use hunt store membership state to conditionally display admin UI elements
- Handle fetch errors gracefully with alerts and back navigation buttons
- Update admin UI logic to depend on membership state instead of user role
- Add membership state update after API calls in hunt, quest, teams, and admin pages
- Refactor UI templates to show error messages when fetch fails
- Centralize membership logic for better authorization control in frontend
This commit is contained in:
2026-07-30 22:33:47 +02:00
parent cfda014760
commit 370ba3406f
7 changed files with 351 additions and 261 deletions
+12 -3
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { sluggy } from '#imports';
import { useHuntStore } from '~/stores/hunt';
import { useTitleStore } from '~/stores/title';
const { loggedIn, clear, user } = useUserSession();
@@ -8,10 +9,18 @@ const localePath = useLocalePath();
const route = useRoute();
const breakpoints = useBreakpoint();
const titleStore = useTitleStore();
const huntStore = useHuntStore();
const isSidebarVisible = ref(breakpoints.mdUp);
const slugs = computed(() => checkSlug(route.params));
const isHuntAdmin = computed(
() =>
slugs.value?.huntSlug !== undefined &&
huntStore.huntId === slugs.value.huntSlug.id &&
huntStore.isMember
);
</script>
<template>
@@ -75,7 +84,7 @@ const slugs = computed(() => checkSlug(route.params));
</VaSidebarItemContent>
</VaSidebarItem>
<VaSidebarItem
v-if="slugs?.huntSlug && user?.role === 'ADMIN'"
v-if="slugs?.huntSlug && isHuntAdmin"
text-color="danger"
hover-color="danger"
active-color="onDanger"
@@ -90,7 +99,7 @@ const slugs = computed(() => checkSlug(route.params));
</VaSidebarItemContent>
</VaSidebarItem>
<VaSidebarItem
v-if="slugs?.huntSlug && user?.role === 'ADMIN'"
v-if="slugs?.huntSlug && isHuntAdmin"
text-color="danger"
hover-color="danger"
active-color="onDanger"
@@ -125,7 +134,7 @@ const slugs = computed(() => checkSlug(route.params));
</VaSidebarItemContent>
</VaSidebarItem>
<VaSidebarItem
v-if="slugs?.huntSlug && slugs?.questSlug && user?.role === 'ADMIN'"
v-if="slugs?.huntSlug && slugs?.questSlug && isHuntAdmin"
text-color="danger"
hover-color="danger"
active-color="onDanger"