Add global auth state with composable for reactive login status
This commit is contained in:
@@ -400,12 +400,9 @@ const isMobileMenuOpen = ref(false)
|
||||
const mobileSubmenu = ref(null)
|
||||
const mannschaften = ref([])
|
||||
const hasGalleryImages = ref(false)
|
||||
const isLoggedIn = ref(false)
|
||||
const userRole = ref(null)
|
||||
|
||||
const isAdmin = computed(() => {
|
||||
return userRole.value === 'admin' || userRole.value === 'vorstand'
|
||||
})
|
||||
// Use global auth state
|
||||
const { isLoggedIn, userRole, isAdmin, checkAuth } = useAuth()
|
||||
|
||||
// Automatisches Setzen des Submenus basierend auf der Route
|
||||
const currentSubmenu = computed(() => {
|
||||
@@ -486,21 +483,10 @@ const checkGalleryImages = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const checkAuthStatus = async () => {
|
||||
try {
|
||||
const response = await $fetch('/api/auth/status')
|
||||
isLoggedIn.value = response.isLoggedIn
|
||||
userRole.value = response.role
|
||||
} catch (error) {
|
||||
isLoggedIn.value = false
|
||||
userRole.value = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadMannschaften()
|
||||
checkGalleryImages()
|
||||
checkAuthStatus()
|
||||
checkAuth()
|
||||
})
|
||||
|
||||
const toggleSubmenu = (menu) => {
|
||||
|
||||
Reference in New Issue
Block a user