Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 119 #24

Open
Xfiles81 opened this issue Sep 6, 2023 · 2 comments
Open

Lesson 119 #24

Xfiles81 opened this issue Sep 6, 2023 · 2 comments

Comments

@Xfiles81
Copy link

Xfiles81 commented Sep 6, 2023

onShapshot does not fire and i do not receive the date realated to message, name and createdAt fiellds in the ChatWindow

@Sir1usBl4ck
Copy link

same

@Light006
Copy link

Here is a fix in case anyone else needed it:

import { ref } from 'vue'
import { projectFirestore } from '../firebase/config'
import { collection, query, orderBy, onSnapshot } from "firebase/firestore";

const getCollection = (firebaseCollection) => {
const documents = ref(null)
const error = ref(null)

const docRef = collection(projectFirestore, firebaseCollection)

const q = query(docRef, orderBy('createdAt'))

onSnapshot(q, (snap) => {
    let results = []
    snap.docs.forEach(doc => {
        doc.data().createdAt && results.push({ ...doc.data(), id: doc.id })
    })
    documents.value = results
    error.value = null
}, (err) => {
    console.log(err.message)
    documents.value = null
    error.value = 'could not fetch data'
})

return { documents, error }

}

export default getCollection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants