I’m new with firebase. I’m building a simple app with Vuejs and Firebase by following a Udemy course.
I’m curious about a strange thing. I’m trying to understand but I can’t.
I know, the onChange event is always running. With old version, when I logout and loggin with other user. The data still belong to the privous user
old version
async getNotes() {
this.notesLoaded = false
onSnapshot(notesCollectionQuery, (querySnapshot) => {
let notes = []
querySnapshot.forEach((doc) => {
let note = {
id: doc.id,
content: doc.data().content,
date: doc.data().date
}
notes.push(note)
})
this.notes = notes
this.notesLoaded = true
})
},
new version will fix that issue.
if (getNotesSnapshot) getNotesSnapshot() // unsubscribe from any active listener
getNotesSnapshot = onSnapshot(notesCollectionQuery, (querySnapshot) => {
let notes = []
querySnapshot.forEach((doc) => {
let note = {
id: doc.id,
content: doc.data().content,
date: doc.data().date
}
notes.push(note)
})
this.notes = notes
this.notesLoaded = true
})
},
How it achieve that? Thanks.
Full code is available here