Add authentication check and logout functionality in app.vue

This commit is contained in:
Jennie Robinson Faber 2025-08-23 12:47:40 +01:00
parent ee00a8018e
commit 733a1e9f47
9 changed files with 1294 additions and 1653 deletions

View file

@ -9,6 +9,15 @@
FABER FINANCES
</NuxtLink>
</div>
<div class="flex items-center">
<button
v-if="authenticated"
@click="logout"
class="text-white hover:text-gray-300 px-3 py-2 text-sm font-medium"
>
Logout
</button>
</div>
</div>
</div>
</nav>
@ -23,4 +32,27 @@ useSeoMeta({
titleTemplate: "%s - Faber Finances",
description: "Personal finance and cash flow management system",
});
const authenticated = ref(false)
// Check authentication status
onMounted(async () => {
try {
const { authenticated: isAuth } = await $fetch('/api/auth/check')
authenticated.value = isAuth
} catch (err) {
authenticated.value = false
}
})
// Logout function
const logout = async () => {
try {
await $fetch('/api/auth/logout', { method: 'POST' })
authenticated.value = false
await navigateTo('/login')
} catch (err) {
console.error('Logout error:', err)
}
}
</script>