feat: Added logout function
This commit is contained in:
parent
bbd329a4cf
commit
7678a44945
@ -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>
|
||||
|
4
webv2/server/api/auth/index.delete.ts
Normal file
4
webv2/server/api/auth/index.delete.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export default defineEventHandler((event) => {
|
||||
setCookie(event, 'jwt', '', { httpOnly: true, maxAge: 1 })
|
||||
sendRedirect(event, '/', 302)
|
||||
})
|
Loading…
Reference in New Issue
Block a user