This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.vue
121 lines (107 loc) · 2.62 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
<script lang="ts" setup>
import {
doc,
getDoc,
serverTimestamp,
setDoc,
updateDoc,
} from 'firebase/firestore'
const db = useFirestore()
const user = useCurrentUser()
const {
public: { vuefireVersion, nuxtVuefireVersion },
} = useRuntimeConfig()
const router = useRouter()
const route = useRoute()
watch(user, async (currentUser, previousUser) => {
// redirect to login if they logout and the current route is only for authenticated users
if (
!currentUser &&
previousUser &&
(Array.isArray(route.meta.middleware)
? route.meta.middleware.includes('authenticated')
: route.meta.middleware === 'authenticated')
) {
return router.push({ name: 'login' })
}
// redirect the user if they are logged in but were rejected because the user wasn't ready yet
if (currentUser && typeof route.query.redirect === 'string') {
return router.push(route.query.redirect)
}
// update user info
if (currentUser && !currentUser.isAnonymous) {
console.log('Updating user info...')
const userDoc = doc(db, 'users', currentUser.uid)
const userData = {
displayName: currentUser.displayName,
photoURL: currentUser.photoURL,
lastLogin: serverTimestamp(),
}
const existingUser = await getDoc(userDoc)
if (existingUser.exists()) {
await updateDoc(userDoc, userData)
} else {
await setDoc(userDoc, {
...userData,
joinedAt: serverTimestamp(),
})
}
console.log('User updated')
}
})
</script>
<template>
<div>
<a href="https://nuxt.com" target="_blank">
<img src="@/assets/nuxt.svg" class="logo" alt="Nuxt logo" />
</a>
<a href="https://vuefire.vuejs.org" target="_blank">
<img src="/vuefire.svg" class="logo vuefire" alt="VueFire logo" />
</a>
</div>
<h1>Nuxt + VueFire</h1>
<NavigationLinks />
<NuxtPage />
<p>
<a href="https://github.com/posva/vuefire-nuxt-example">
<img
src="@/assets/github-mark.svg"
alt="GitHub logo"
class="logo github"
/>
Source Code
</a>
- <code>vuefire@{{ vuefireVersion }}</code> -
<code>nuxt-vuefire@{{ nuxtVuefireVersion }}</code>
</p>
</template>
<style scoped>
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter ease-out 0.3s;
}
.logo.vuefire {
height: 7.5em;
}
.logo:hover {
filter: drop-shadow(0 0 2em #00dc82aa);
}
.logo.vuefire:hover {
filter: drop-shadow(0 0 2em #f78200aa);
}
@media screen and (max-width: 425px) {
.logo {
height: 4em;
padding: 0.5em;
}
.logo.vuefire {
height: 5em;
}
}
.logo.github {
height: 1em;
padding: 0 0.15em;
}
</style>