-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAuth.vue
More file actions
46 lines (38 loc) · 1013 Bytes
/
Auth.vue
File metadata and controls
46 lines (38 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<script setup>
/** UI */
import Button from "@/components/ui/Button.vue"
import { Dropdown, DropdownItem } from "@/components/ui/Dropdown"
/** Store */
import { useAuthStore } from "@/store/auth.store.js"
import { useModalsStore } from "@/store/modals.store.js"
const authStore = useAuthStore()
const modalsStore = useModalsStore()
const login = () => {
authStore.login()
}
const logout = async () => {
await authStore.revokeToken()
authStore.logout()
}
onMounted(() => {
authStore.initialize()
})
</script>
<template>
<Dropdown v-if="authStore.isAuthenticated">
<Button type="secondary" size="mini">
<Icon name="address" size="14" color="secondary" />
<span>{{ authStore.user?.username }}</span>
</Button>
<template #popup>
<DropdownItem @click="modalsStore.open('settings')">
Settings
</DropdownItem>
<DropdownItem @click="logout">
Logout
</DropdownItem>
</template>
</Dropdown>
<Button v-else @click="login" type="white" size="mini">Login</Button>
</template>
>