nuxt-community / firebase-module

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

Call firebase function locally in nuxt app #355

Closed kamilcglr closed 3 years ago

kamilcglr commented 3 years ago

Hello, I use nuxt and firebase with the @nuxt/firebase module and I would like to know how to make this.$fireFunc.myFunction call the function in the emulator. Currently I run the command "npm run dev" but it is the function on firebase function that is called and not the one executed in "npm run serve". Thanks in advance

DamianGlowala commented 3 years ago

https://firebase.nuxtjs.org/service-options/functions/#emulatorport

kamilcglr commented 3 years ago

Thank you for your answer, but I don't know if I'm missing something or if I have a bad configuration. I have this in my nuxt.config.js

firebase: {
    config: {
      apiKey: 'x',
      authDomain: 'x',
      databaseURL: 'x',
      projectId: 'x',
      storageBucket: 'x,
      messagingSenderId: 'x',
      appId: 'x',
      measurementId: 'x',
    },

    onFirebaseHosting: true,

    services: {
      auth: true,
      firestore: true,
      functions: true,
      storage: true,
      realtimeDb: true,
      messaging: true,
      performance: true,
      analytics: true,
      remoteConfig: true,
    },

    functions: {
      emulatorPort: 8001,
    },
  },

and this in firebase.json

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "functions": {
    "predeploy": "npm --prefix \"$RESOURCE_DIR\" run build"
  },
  "emulators": {
    "functions": {
      "port": 8001
    }
  }
}

But when I do "firebase emulators:start" and then call the function :

await this.$fire.functions.httpsCallable('sendEmail')({
          text: this.message,
          name: this.firstname + ' ' + this.lastname,
          email: this.email,
        })

calls the function on the cloud and not the one running locally.

DamianGlowala commented 3 years ago

Try it now :)

    services: {
      auth: true,
      firestore: true,
      functions: {
         emulatorPort: 8001
      },
      storage: true,
      realtimeDb: true,
      messaging: true,
      performance: true,
      analytics: true,
      remoteConfig: true,
    }
kamilcglr commented 3 years ago

Thank you very much 🙏