Description
Environment info
firebase-tools:
8.4.3
Platform:
Windows 10
Test case
import * as functions from 'firebase-functions'
exports.onDeviceOnlineChanged = functions.database.ref('/status/{deviceId}')
.onWrite(async (change, context) => {
const ref = change.before.ref.toString()
// do something with the reference
return ref
})
Steps to reproduce
make a change to that node on the realtime database to initiate the function
Expected behavior
No error, this works on the server, but not on the emulator.
Calling the same code directly from the app runs without issues. The call to the change.before.ref
causes the error only when the function is initiated from a trigger.
Calling using the initiated admin.database().ref('/status/${deviceId}')
works normally as in the snippet below
exports.onDeviceChanged = functions.https.onCall(async (data, context) => {
const deviceId = data.deviceId
const status = admin.database().ref(`/status/${deviceId}`)
const deviceFirestoreRef = admin.firestore().collection('devices').doc(deviceId)
const upd = { online: status.toJSON() }
return deviceFirestoreRef.update(upd);
})
Actual behavior
throws the error:
@firebase/database: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://.firebaseio.com
! functions: Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
at fatal (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:341:11)
at parseRepoInfo (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:1295:9)
at RepoManager.databaseFromApp (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:14919:25)
at Object.initStandalone (C:\dev\xyz\functions\node_modules\@firebase\database\dist\index.node.cjs.js:15303:45)
at DatabaseService.getDatabase (C:\dev\xyz\functions\node_modules\firebase-admin\lib\database\database.js:66:23)
at FirebaseApp.database (C:\dev\xyz\functions\node_modules\firebase-admin\lib\firebase-app.js:231:24)
at DataSnapshot.get ref [as ref] (C:\dev\xyz\functions\node_modules\firebase-functions\lib\providers\database.js:279:34)
at C:\dev\xyz\functions\lib\presense.js:7:31
at cloudFunction (C:\dev\xyz\functions\node_modules\firebase-functions\lib\cloud-functions.js:132:23)
at C:\Users\P\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:563:20
! Your function was killed because it raised an unhandled error.