Open simeon9696 opened 3 years ago
I'm using this atm but I'm not sure if this is the right way to do it
generate:{
async routes(){
try {
const { default:firebase } = await import('firebase/app');
await import('firebase/firestore');
const config ={
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
databaseURL: process.env.databaseURL,
projectId: process.env.projectId,
storageBucket: process.env.storageBucket,
messagingSenderId: process.env.messagingSenderId,
appId: process.env.appId,
measurementId: process.env.measurementId
}
if (!firebase.apps.length) {
firebase.initializeApp(config);
}
const app = firebase.apps[0];
const l = await app.firestore().collection('products').get();
const products = l.docs.map(doc=> { return {payload: {...doc.data(), id: doc.id}, route: `/product/${doc.data().category}`}})
return products;
} catch (error) {
console.error(error)
}
}
Hi, I got an issue with this line firebase.apps.length
it says Cannot read property 'apps' of undefined
did you know something?
Hi, I got an issue with this line
firebase.apps.length
it saysCannot read property 'apps' of undefined
did you know something?
I also have this problem.
@Dwiga @luckstar77 Check your firebase version. Make sure you use this module with firebase SDK <= 8
Thank you, I downgrade to v7.24.0, it is solved.
@requiem202 hi, thank you it works after I downgrade my firebase SDK to 7.24.0
@luckstar77 @Dwiga you can try firebase v8.10.0
but definitely not v9+
Not a bug just a general question. How would we access
firestore
in the generate hook?