Refactor some variable and method names

This commit is contained in:
2022-10-28 21:48:13 +02:00
parent 58fac72355
commit 9419a5904e
7 changed files with 119 additions and 62 deletions

View File

@@ -6,6 +6,8 @@
<script>
import { onAuthStateChanged } from 'firebase/auth'
import { doc, getDoc } from 'firebase/firestore'
import { UserConverter } from '~/plugins/user'
export default {
name: 'IndexPage',
@@ -17,15 +19,27 @@ export default {
onAuthStateChanged(this.$auth, (user) => {
this.$store.commit('initFirebase')
if (user) {
// User is signed in; redirect to main page (dashboard)
this.$store.commit('setUserLoggedIn', true)
this.$router.push({ name: 'dashboard' })
// User is signed in; get user data from db, then redirect to main page (dashboard)
this.getUser()
} else {
// User is signed out; redirect to login page
this.$store.commit('setUserLoggedIn', false)
this.$store.commit('setUser', null)
this.$router.push({ name: 'login' })
}
})
},
methods: {
getUser () {
const ref = doc(this.$db, `benutzer/${this.$auth.currentUser.uid}`).withConverter(UserConverter)
getDoc(ref).then((docSnap) => {
if (docSnap.exists()) {
this.$store.commit('setUser', docSnap.data())
this.$router.push({ name: 'dashboard' })
} else {
this.$toast({ content: 'Benutzer konnte in DB nicht gefunden werden!', color: 'error' })
}
})
}
}
}
</script>