Skip to content Skip to sidebar Skip to footer

Cloud Functions Cant Not Get Token From Realtime Database

im trying to send message from function but its always got 'Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array' but here is where my

Solution 1:

I think you're trying to use the value of the token property of the user who triggered the Cloud Function. In that case you don't need to attach a separate listener, as the value is already available inside the context parameter.

exports.mess = functions.database.ref('/path/{uid}')
.onWrite(event => {
    let token = event.after.child('token').val()
    const payload = {
        notification: {
            title: 'You have been invited to a trip.',
            body: 'Tap here to check it out!'
        }
    };

    return admin.messaging().sendToDevice(snapshot.val(), payload)
});

Post a Comment for "Cloud Functions Cant Not Get Token From Realtime Database"