Firebase Cloud Function Finished With Status ''error''
Solution 1:
You're using the old beta API with the new 1.x version of the SDK. The way that database events work has changed. The changes for the entire SDK are summarized here. onWrite events now take two parameters, a change and a context. The change contains the before and after snapshots, and the context contains the wildcard values.
To get the userId wildcard, you would now say:
exports.sendSignUpNotification = functions.database.ref(`/users/{userId}`).onWrite((change, context) => {
const userId = context.params.userId
Please see the documentation for more current examples.
Also in your code this line has a bug:
let token = admin.database().ref(`/users/{userId}/notificationTokens`).once('value');
The JavaScript syntax for variable interpolation in a backtick delimited string requires a dollar sign:
`/users/${userId}/notificationTokens`
That line has yet another bug. You're not making use of the promise returned by once() to actually get a hold of the value in the database. token
is going to contain that promise, not the contents of the database.
And you're also going to have to return a promise that resolves when all the async work is done in the function, which you're currently not doing.
Post a Comment for "Firebase Cloud Function Finished With Status ''error''"