nuxt-community / firebase-module

🔥 Easily integrate Firebase into your Nuxt project. 🔥
https://firebase.nuxtjs.org
MIT License
640 stars 98 forks source link

When running locally, do callable functions work with ssr? #336

Closed harrycheung closed 3 years ago

harrycheung commented 3 years ago

I'm experiencing different behaviors running my nuxt app locally vs in a production environment (google cloud run).

To illustrate, I have this in my component

  async fetch(context) {
    try {
      console.log('before product-get', context.params.id)
      const { data } = await context.$fireFunc.httpsCallable('product-get')({ id: context.params.id })
      console.log('after product-get', data.product)
    } catch (error) {
      console.log(error)
    }
  }

The code runs fine on cloud run and firebase, but if I attempt to run locally with the firebase emulator, I get the following output:

before product-get ztfZw8WgKW0WCs75gE9b                                                                           11:44:37
Headers is not defined                                                                                            11:44:37

  at Service.<anonymous> (node_modules/@firebase/functions/dist/index.node.cjs.js:522:25)
  at step (node_modules/tslib/tslib.js:141:27)
  at Object.next (node_modules/tslib/tslib.js:122:57)
  at node_modules/tslib/tslib.js:115:75
  at new Promise (<anonymous>)
  at Object.__awaiter (node_modules/tslib/tslib.js:111:16)
  at Service.call (node_modules/@firebase/functions/dist/index.node.cjs.js:513:22)
  at node_modules/@firebase/functions/dist/index.node.cjs.js:449:26
  at Object.fetch (pages/p/_id/h/_handle.js:3941:63)
  at Promise.all.Components.map.Component (server.js:2824:39)
  at Array.map (<anonymous>)
  at module.exports../functions/.nuxt/server.js.__webpack_exports__.default (server.js:2807:51)
  at process._tickCallback (internal/process/next_tick.js:68:7)

I enable/disable the emulator via emulatorPort in nuxt.config.js.

I'm hoping this is something other people have tried before and this is a misconfiguration on my part.

lupas commented 3 years ago

Hey @harrycheung

Sorry for the late response - was quite busy with other things. I'll try to test it out on my side this week and let you know if I can reproduce this issue. Imho this doesn't seem to be a problem related to this module and as far as I know httpsCallable should work with the local emulator...

I'll see what I can find out - let me know if you already figured it out.

br, Pascal

lupas commented 3 years ago

Hey @harrycheung

I can't reproduce this error. As you can see in the demo app, we do a httpsCallable right here and that works fine for me locally with the Functions emulator.

Could you have a look at the demo project and see if something different on your side? Maybe if you compare the two you can find the issue.

If you can't find anything could you try to create a sample app where you run into the issue?

Thanks!

lupas commented 3 years ago

Closing due to inactivity.