Replace composable with Pinia store for persistent auth state
This commit is contained in:
@@ -93,30 +93,32 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { User, ChevronUp } from 'lucide-vue-next'
|
||||
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
const currentYear = new Date().getFullYear()
|
||||
const isMemberMenuOpen = ref(false)
|
||||
|
||||
// Use global auth state
|
||||
const { isLoggedIn, isAdmin, logout: authLogout, checkAuth } = useAuth()
|
||||
// Reactive auth state from store
|
||||
const isLoggedIn = computed(() => authStore.isLoggedIn)
|
||||
const isAdmin = computed(() => authStore.isAdmin)
|
||||
|
||||
const toggleMemberMenu = () => {
|
||||
isMemberMenuOpen.value = !isMemberMenuOpen.value
|
||||
}
|
||||
|
||||
const handleLogout = async () => {
|
||||
await authLogout()
|
||||
await authStore.logout()
|
||||
isMemberMenuOpen.value = false
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
// Check auth status on mount
|
||||
onMounted(() => {
|
||||
checkAuth()
|
||||
authStore.checkAuth()
|
||||
})
|
||||
|
||||
// Close menu when clicking outside
|
||||
|
||||
Reference in New Issue
Block a user