add frontend logout
This commit is contained in:
parent
d457c766c3
commit
c15c13fd38
2 changed files with 58 additions and 0 deletions
|
|
@ -101,6 +101,20 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function logout(): Promise<void> {
|
||||||
|
try {
|
||||||
|
await fetch(`${API_BASE}/api/logout`, {
|
||||||
|
method: 'POST',
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
user.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user,
|
user,
|
||||||
loading,
|
loading,
|
||||||
|
|
@ -108,5 +122,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
fetchMe,
|
fetchMe,
|
||||||
login,
|
login,
|
||||||
|
logout,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,23 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
import BrandWordmark from '@/components/BrandWordmark.vue'
|
import BrandWordmark from '@/components/BrandWordmark.vue'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
async function handleLogout(): Promise<void> {
|
||||||
|
await authStore.logout()
|
||||||
|
await router.push({ name: 'login' })
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="dashboard-page">
|
<main class="dashboard-page">
|
||||||
<header>
|
<header>
|
||||||
<BrandWordmark theme="dark" />
|
<BrandWordmark theme="dark" />
|
||||||
|
<button type="button" class="logout-button" @click="handleLogout">Log out</button>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
|
|
@ -29,10 +41,41 @@ import BrandWordmark from '@/components/BrandWordmark.vue'
|
||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
|
display: flex;
|
||||||
width: min(100%, 76rem);
|
width: min(100%, 76rem);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logout-button {
|
||||||
|
min-height: 2.75rem;
|
||||||
|
padding: 0.7rem 1.1rem;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 0.7rem;
|
||||||
|
color: #fffdf7;
|
||||||
|
background: #183a31;
|
||||||
|
box-shadow: 0 0.55rem 1.2rem rgb(24 58 49 / 14%);
|
||||||
|
font-size: 0.82rem;
|
||||||
|
font-weight: 750;
|
||||||
|
cursor: pointer;
|
||||||
|
transition:
|
||||||
|
background-color 160ms ease,
|
||||||
|
transform 160ms ease,
|
||||||
|
box-shadow 160ms ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-button:hover {
|
||||||
|
background: #285c4e;
|
||||||
|
box-shadow: 0 0.7rem 1.4rem rgb(24 58 49 / 18%);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-button:focus-visible {
|
||||||
|
outline: 3px solid rgb(86 127 112 / 34%);
|
||||||
|
outline-offset: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
width: min(100%, 42rem);
|
width: min(100%, 42rem);
|
||||||
margin: clamp(6rem, 18vh, 12rem) auto 0;
|
margin: clamp(6rem, 18vh, 12rem) auto 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue