我是云函数的初学者。这是我的第一个函数。不知道如何解决此错误。任何人都请告诉我需要进行哪些更正。我什至不知道javascript的基础知识 我的Whats App号码6282133414
这是我的数据库
这是我的云功能
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database
.ref("/tips/{pushid}")
.onWrite( (change,context) => {
const mtitle = change.after.val().call;
const mbody = change.after.val().message;
const payload = {
notification: {
title: mtitle,
body: mbody
}
};
admin.database().ref('/fcmtoken').once('value').then(alltokens =>{
if(alltokens.val()){
console.log(alltokens.val());
console.log('token available');
return admin.messaging().sendToDevice(alltokens.val(),payload);
}
else{
console.log('No token available');
}
});
});
这是错误
Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array.
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor](/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseMessagingError.PrefixedFirebaseError [as constructor](/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseMessagingError(/user_code/node_modules/firebase-admin/lib/utils/error.js:241:16)
at Messaging.validateRegistrationTokensType(/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:872:19)
at Messaging.sendToDevice(/user_code/node_modules/firebase-admin/lib/messaging/messaging.js:493:14)
at admin.database.ref.once.then.alltokens (/user_code/index.js:20:38)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)