firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Fail fast on attempt to trigger on another project's Realtime Database

Open snarfed opened this issue 3 years ago • 0 comments

Hi all! Thanks for Firebase Functions, it's great!

I recently tried to set up a Firebase Cloud Function to trigger on a Realtime Database owned by a different project: the Hacker News API. I passed databaseUrl: https://hacker-news.firebaseio.com/ to admin.initializeApp() and it deployed fine, but it never triggered.

I eventually learned that Firebase just doesn't support triggering across projects like this. Fair enough. Could you consider failing fast and reporting an error in this case? That would have saved me a fair amount of debugging.

Code below. Thanks in advance!

Related issues

https://stackoverflow.com/questions/73355121/firebase-cloud-function-not-triggering-on-different-apps-realtime-database

[REQUIRED] Version info

node: v16.16.0

firebase-functions:

firebase-tools:

11.6.0

firebase-admin:

[REQUIRED] Test case

const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp({databaseUrl: 'https://hacker-news.firebaseio.com/'})

exports.itemUpdated = functions.database.ref('/v0/item/{id}').onCreate((snapshot, context) => {
      functions.logger.log('Item: ', context.params.id, snapshot.val())
      return null
})

[REQUIRED] Steps to reproduce

Deploy this function ^

[REQUIRED] Expected behavior

Triggers on every new /v0/item/{id} created.

[REQUIRED] Actual behavior

Never triggers.

Were you able to successfully deploy your functions?

yes

snarfed avatar Aug 15 '22 16:08 snarfed