add navbar logout
This commit is contained in:
parent
6018764731
commit
356725ceeb
1 changed files with 20 additions and 1 deletions
|
|
@ -1,13 +1,23 @@
|
|||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
onMounted(() => {
|
||||
void authStore.fetchUser()
|
||||
})
|
||||
|
||||
function goToAbout(): void {
|
||||
router.push('/about')
|
||||
}
|
||||
|
||||
async function handleLogout(): Promise<void> {
|
||||
await authStore.logout()
|
||||
}
|
||||
|
||||
const navItems = [
|
||||
{ label: 'Torah Media', href: '/media', icon: '▶' },
|
||||
{ label: 'About', href: '/about', icon: 'ⓘ' },
|
||||
|
|
@ -143,6 +153,15 @@ const projects: Project[] = [
|
|||
</span>
|
||||
<span>{{ item.label }}</span>
|
||||
</a>
|
||||
<button
|
||||
v-if="authStore.isAuthenticated"
|
||||
data-cy="navbar-logout"
|
||||
type="button"
|
||||
class="site-header__nav-link"
|
||||
@click="handleLogout"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue