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

Use in generate in nuxt.config.js #554

Open
simeon9696 opened this issue Jun 20, 2021 · 7 comments
Open

Use in generate in nuxt.config.js #554

simeon9696 opened this issue Jun 20, 2021 · 7 comments

Comments

@simeon9696
Copy link

Not a bug just a general question. How would we access firestore in the generate hook?

@simeon9696
Copy link
Author

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)
      }
    }

@Dwiga
Copy link

Dwiga commented Sep 9, 2021

Hi, I got an issue with this line firebase.apps.length
it says Cannot read property 'apps' of undefined did you know something?

@luckstar77
Copy link

Hi, I got an issue with this line firebase.apps.length
it says Cannot read property 'apps' of undefined did you know something?

I also have this problem.

@vacharanon
Copy link

@Dwiga @luckstar77 Check your firebase version. Make sure you use this module with firebase SDK <= 8

@luckstar77
Copy link

Thank you, I downgrade to v7.24.0, it is solved.

@Dwiga
Copy link

Dwiga commented Sep 12, 2021

@requiem202 hi, thank you it works after I downgrade my firebase SDK to 7.24.0

@simeon9696
Copy link
Author

@luckstar77 @Dwiga you can try firebase v8.10.0 but definitely not v9+

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

4 participants