From a18491a1a25dc5e73518c48d0895210c8615800e Mon Sep 17 00:00:00 2001 From: Xeovalyte Date: Sun, 22 Jan 2023 15:34:32 +0100 Subject: [PATCH] added more info --- frontend/app.vue | 95 +++++++-------- frontend/pages/settings/index.vue | 136 +++++++++++----------- frontend/pages/settings/moreinfo.vue | 36 ++++++ frontend/pages/settings/privacypolicy.vue | 32 ++--- 4 files changed, 168 insertions(+), 131 deletions(-) create mode 100644 frontend/pages/settings/moreinfo.vue diff --git a/frontend/app.vue b/frontend/app.vue index 6537447..457fb93 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -48,61 +48,61 @@ const users = ref([]) const messaging = ref(null) onMounted(() => { - auth.value = getAuth() + auth.value = getAuth() - if (process.client) { - if ('serviceWorker' in navigator && window.isSecureContext) { - Device.getInfo().then(info => { - if (info.platform === 'web') registerSW() - }); - + if (process.client) { + if ('serviceWorker' in navigator && window.isSecureContext) { + Device.getInfo().then(info => { + if (info.platform === 'web') registerSW() + }); + + } + } + + onAuthStateChanged(auth.value, async (usr) => { + if (usr) { + user.value = usr + + let docRef = doc(db, "users", user.value.uid); + let docSnap = await getDoc(docRef); + + if (docSnap.exists()) { + const data = docSnap.data() + userData.value = data + getPersons(userData.value.relatiecodes) + } else { + setTimeout(() => window.location.reload(true), 1000) } + + if (!userData.value.sendNews && route.path === '/news/newmessage') navigateTo('/') + if (!userData.value.admin && route.path.startsWith('/settings/admin')) navigateTo('/') + + isAuthenticated.value = true + + logDeviceInfo() + + } else { + isAuthenticated.value = false + user.value = null + userData.value = null + userPersons.value = [] } - onAuthStateChanged(auth.value, async (usr) => { - if (usr) { - user.value = usr - - let docRef = doc(db, "users", user.value.uid); - let docSnap = await getDoc(docRef); - - if (docSnap.exists()) { - const data = docSnap.data() - userData.value = data - getPersons(userData.value.relatiecodes) - } else { - setTimeout(() => window.location.reload(true), 1000) - } - - if (!userData.value.sendNews && route.path === '/news/newmessage') navigateTo('/') - if (!userData.value.admin && route.path.startsWith('/settings/admin')) navigateTo('/') - - isAuthenticated.value = true - - logDeviceInfo() - - } else { - isAuthenticated.value = false - user.value = null - userData.value = null - userPersons.value = [] - } - - userLoaded.value = true - }) + userLoaded.value = true + }) }) const getPersons = async (persons) => { - userPersons.value = []; + userPersons.value = []; - for (let i = 0; i < persons.length; i++) { - const docRef = doc(db, "ledenlijst", persons[i]); - const docSnap = await getDoc(docRef); + for (let i = 0; i < persons.length; i++) { + const docRef = doc(db, "ledenlijst", persons[i]); + const docSnap = await getDoc(docRef); - if (docSnap.exists()) { - userPersons.value.push(docSnap.data()) - } + if (docSnap.exists()) { + userPersons.value.push(docSnap.data()) } + } } const setupNotifications = () => { @@ -173,7 +173,7 @@ const registerFCM = () => { if (currentToken) { console.log(currentToken) - await useFetch('/api/subscribetotopic', { + const { error} = await useFetch('/api/subscribetotopic', { method: 'post', body: { topic: 'all', registrationToken: currentToken } }) @@ -183,6 +183,7 @@ const registerFCM = () => { return toast.error('Error tijdens het registreren van push notifications') } + registrationToken.value = currentToken console.log('Subscribed to topic!') } else { // Show permission request UI @@ -220,7 +221,7 @@ const logDeviceInfo = async () => { const ledenlijst = ref([]) -provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, users, userAllPersons, getPersons, calEvents, news, registrationToken, contestTimes, competitors }) +provide('firebase', { db, ledenlijst, isAuthenticated, user, userData, userPersons, auth, users, userAllPersons, getPersons, calEvents, news, registrationToken, contestTimes, competitors, registrationToken })