-
Notifications
You must be signed in to change notification settings - Fork 13
/
app.vue
161 lines (148 loc) · 3.74 KB
/
app.vue
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<script setup lang="ts">
import type { H3Error } from 'h3'
const toast = useToast()
const router = useRouter()
const { loggedIn, user, clear } = useAuth()
const { modal } = useAuthModal()
const items = [
[
{
label: 'Account',
slot: 'account',
disabled: true,
},
],
[
{
label: 'Home',
icon: 'i-ph-house-duotone',
click: () => router.replace({ name: 'index' }),
},
{
label: 'About',
icon: 'i-ph-info-duotone',
click: () => router.replace({ name: 'about' }),
},
{
label: 'Profile',
icon: 'i-ph-user-duotone',
click: () => router.replace({ name: 'profile' }),
},
],
[
{
label: 'Sign out',
icon: 'i-ph-sign-out',
click: () => {
clear()
toast.add({
color: 'amber',
title: 'Logged out!',
icon: 'i-ph-sign-out',
description: 'user signed out successfully.',
})
},
},
],
]
function onLogin(user: string) {
modal.value = false
toast.add({
title: 'Logged In',
icon: 'i-ph-sign-in',
description: `${user} logged in successfully.`,
})
}
function onRegister(user: string) {
modal.value = false
toast.add({
title: 'Registered',
icon: 'i-ph-sign-in',
description: `${user} registered successfully.`,
})
}
function onError(error: H3Error) {
toast.add({
title: `Error ${error.statusCode}`,
icon: 'i-ph-warning-duotone',
description: error.statusMessage,
})
}
</script>
<template>
<Html>
<Body>
<NuxtLoadingIndicator />
<UHeader>
<template #logo>
<Logo class="mt-2 w-64 h-20" />
</template>
<template #panel-button>
<span />
</template>
<template #right>
<Socials />
<UDropdown v-if="loggedIn" :items="items" mode="hover">
<UAvatar :src="`https://unavatar.io/gravatar/${user.email}`" class="bg-gray-200 dark:bg-neutral-800" />
<template #account>
<div class="text-left w-full">
<p>
Signed in as
</p>
<p class="truncate font-medium">
{{ user.email }}
</p>
</div>
</template>
</UDropdown>
<UButton v-else color="gray" @click="modal = true">
Login
</UButton>
</template>
</UHeader>
<UMain>
<UContainer>
<NuxtPage />
</UContainer>
</UMain>
<UFooter :ui="{ wrapper: 'border-t border-gray-400/20' }">
<template #left>
© {{ new Date().getFullYear() }}
<NuxtLink class="underline" to="https://github.com/arashsheyda/nuxt-fullstack" target="_blank">
MIT License
</NuxtLink>
</template>
<template #center>
<span class="flex items-center text-sm">
Powered by
<ULink class="m-1" to="https://nuxt.com" target="_blank">
<UIcon class="w-5 h-5 mt-1" name="i-logos-nuxt-icon" />
</ULink>
<span class="mx-2">
|
</span>
Hosted on
<ULink class="m-1" to="https://vercel.com" target="_blank">
<UIcon class="w-5 h-5 mt-1" name="i-logos-vercel-icon" />
</ULink>
</span>
</template>
<template #right>
<Socials />
</template>
</UFooter>
<UModal v-model="modal">
<Auth @onLogin="onLogin" @onRegister="onRegister" @orError="onError" />
</UModal>
<Teleport to="body">
<UNotifications />
</Teleport>
</Body>
</Html>
</template>
<style>
span[class^="i-"] {
background-size: contain;
background-position: center;
}
</style>