mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-06-07 05:57:41 +00:00
show logout button
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
1d9aae5c5c
commit
7ae17b11e9
8 changed files with 27 additions and 15 deletions
|
@ -5,13 +5,18 @@
|
||||||
<div @click="() => toggleDark()">
|
<div @click="() => toggleDark()">
|
||||||
<IconLightDark class="h-6 w-6 cursor-pointer" />
|
<IconLightDark class="h-6 w-6 cursor-pointer" />
|
||||||
</div>
|
</div>
|
||||||
<!-- <div><IconMenu class="h-8 w-8 cursor-pointer"></IconMenu></div> -->
|
<div v-if="isAuthenticated" @click="() => setToken('')">
|
||||||
|
<IconLogout class="h-6 w-6 cursor-pointer"></IconLogout>
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useDark, useToggle } from '@vueuse/core'
|
import { useDark, useToggle } from '@vueuse/core'
|
||||||
import { IconLightDark, IconMenu } from '@/components/icons'
|
import { IconLightDark, IconLogout } from '@/components/icons'
|
||||||
|
import { useAuth } from '@/composables/'
|
||||||
|
|
||||||
|
const { isAuthenticated, setToken } = useAuth()
|
||||||
|
|
||||||
const toggleDark = useToggle(useDark())
|
const toggleDark = useToggle(useDark())
|
||||||
</script>
|
</script>
|
||||||
|
|
8
src/components/icons/IconLogout.vue
Normal file
8
src/components/icons/IconLogout.vue
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<template>
|
||||||
|
<svg viewBox="0 0 24 24">
|
||||||
|
<path
|
||||||
|
d="M16 17v-3H9v-4h7V7l5 5l-5 5M14 2a2 2 0 0 1 2 2v2h-2V4H5v16h9v-2h2v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9z"
|
||||||
|
fill="currentColor"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
</template>
|
|
@ -1,8 +0,0 @@
|
||||||
<template>
|
|
||||||
<svg viewBox="0 0 24 24">
|
|
||||||
<path
|
|
||||||
d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"
|
|
||||||
fill="currentColor"
|
|
||||||
></path>
|
|
||||||
</svg>
|
|
||||||
</template>
|
|
|
@ -5,5 +5,5 @@ export { default as IconLink } from './IconLink.vue'
|
||||||
export { default as IconSpinner } from './IconSpinner.vue'
|
export { default as IconSpinner } from './IconSpinner.vue'
|
||||||
export { default as IconNoGift } from './IconNoGift.vue'
|
export { default as IconNoGift } from './IconNoGift.vue'
|
||||||
export { default as IconLightDark } from './IconLightDark.vue'
|
export { default as IconLightDark } from './IconLightDark.vue'
|
||||||
export { default as IconMenu } from './IconMenu.vue'
|
export { default as IconLogout } from './IconLogout.vue'
|
||||||
export { default as IconCloudQuestion } from './IconCloudQuestion.vue'
|
export { default as IconCloudQuestion } from './IconCloudQuestion.vue'
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
export * from './useWishlistsStore'
|
export * from './useWishlistsStore'
|
||||||
export * from './useWishlistStore'
|
export * from './useWishlistStore'
|
||||||
export * from './useModal'
|
export * from './useModal'
|
||||||
|
export * from './useAxios'
|
||||||
|
export * from './useAuth'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { readonly } from 'vue'
|
import { computed, readonly } from 'vue'
|
||||||
import { useStorage } from '@vueuse/core'
|
import { useStorage } from '@vueuse/core'
|
||||||
|
|
||||||
const state = useStorage('auth-token', '')
|
const state = useStorage('auth-token', '')
|
||||||
|
@ -7,9 +7,14 @@ const setToken = (token: string): void => {
|
||||||
state.value = token
|
state.value = token
|
||||||
}
|
}
|
||||||
|
|
||||||
export default () => {
|
const isAuthenticated = computed(() => {
|
||||||
|
return state.value !== ''
|
||||||
|
})
|
||||||
|
|
||||||
|
export const useAuth = () => {
|
||||||
return {
|
return {
|
||||||
setToken,
|
setToken,
|
||||||
|
isAuthenticated,
|
||||||
token: readonly(state),
|
token: readonly(state),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import axios, {
|
||||||
import { apiConfig } from '@/config'
|
import { apiConfig } from '@/config'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import router from '../router'
|
import router from '../router'
|
||||||
import useAuth from './useAuth'
|
import { useAuth } from './useAuth'
|
||||||
|
|
||||||
export interface CustomAxiosError extends AxiosError {
|
export interface CustomAxiosError extends AxiosError {
|
||||||
ignore: boolean
|
ignore: boolean
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { useRouter } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { Form } from 'vee-validate'
|
import { Form } from 'vee-validate'
|
||||||
import { object, string } from 'yup'
|
import { object, string } from 'yup'
|
||||||
import useAuth from '@/composables/useAuth'
|
import { useAuth } from '@/composables'
|
||||||
import BaseButton from '@/components/BaseButton.vue'
|
import BaseButton from '@/components/BaseButton.vue'
|
||||||
import TextInput from '@/components/TextInput.vue'
|
import TextInput from '@/components/TextInput.vue'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue