feat: Added logout function

This commit is contained in:
Xeovalyte 2023-06-26 15:16:24 +02:00
parent bbd329a4cf
commit 7678a44945
3 changed files with 24 additions and 0 deletions

View File

@ -15,5 +15,25 @@
<Icon size="1.5em" name="heroicons:map" class="mr-2" />
Map
</NuxtLink>
<div class="mb-5 mt-auto flex w-full items-center rounded bg-black/0 p-2 text-lg hover:cursor-pointer hover:bg-black/20" @click="logout">
<Icon size="1.5em" name="heroicons:arrow-right-on-rectangle" class="mr-2" />
Logout
</div>
</div>
</template>
<script setup>
const logout = async () => {
try {
await useFetch('/api/auth', {
method: 'DELETE'
})
navigateTo('/login')
} catch (e) {
console.error(e)
useToast().add({ title: e.statusMessage, color: 'red' })
}
}
</script>

View File

@ -0,0 +1,4 @@
export default defineEventHandler((event) => {
setCookie(event, 'jwt', '', { httpOnly: true, maxAge: 1 })
sendRedirect(event, '/', 302)
})