I am not sure if this is expected behaviour, but in short, I have/ had a problem where my Universal-mode Nuxt app could not read from Firebase following a refresh of the page. This is because the request came from the server and therefore was being seen by Firebase as an unauthenticated user. I worked around it by forcing SPA mode on the affected page, and it works, but I don't like it as a solution.
Reason this happened is that I was/ am using the Firebase client library (So making the call from the client). I am using Nuxt's fetch() hook to invoke the read action. I used the client library as I (perhaps naively) assumed that this was better for page performance.
To stop refresh failing I should be (I believe) appending fetchOnServer: false to the fetch hook as per the Nuxt docs.
However this does not solve the issue.
I suspect this is because a refresh is not invoking Nuxt/ Vue functions in the same way as navigating to the page via the Nuxt router does. Is this correct? (I can see even with fetchOnServer set to False fetch() still causes server- side requests to Firebase, which fail, as expected). Is there another way around this other than forcing SPA on the page as above? If not, I may look at using the Firebase-Admin library.
Appreciate any feedback on this.
EDIT: Here is an example query I am running in SPA mode currently - this returns all events that a given user is allowed to access. The result is returned to Vuex for client rendering of course :)
async getListOfEvents(uid) {
fireDb = firebase.firestore()
await firebase.auth().currentUser
const pList = fireDb
.collection('presentations')
.where('usersWithPerms', 'array-contains', uid)
.where('status', '==', 'ACTIVE-VISIBLE')
try {
const messageDoc = await pList.get()
const aVP = []
let rObj = {}
messageDoc.forEach(function (childSnapshot) {
const o = childSnapshot.data()
rObj.pName = o.eventName
rObj.synopsis = o.synopsis
rObj.urlSlug = o.urlSlug
rObj.owner = o.owner === uid
aVP.push(rObj)
rObj = {}
})
return aVP
} catch (e) {
console.log(`Error during getting LIST of events! ${e}`)
}
},```