Reputation: 1659
i am trying to fetch firebase database in functions but I can't figure out what's causing the error. here's my code
exports.test = functions.https.onCall(async (data, context) => {
console.log(data)
const sessionID = data.sessionID
const snapshot = await admin.database().ref('/test/'+sessionID).once('value');
console.log(snapshot);
return snapshot
})
this is how I am calling it from client side javascript
function callServer(){
var signInCartIn = firebase.functions().httpsCallable('signInCartIn');
var cartInfo = {
"sessionID":"23234",
"log":"6425",
"cuso_id":"cus_IP83EOJ9843s",
"pjo_id":"tm_1HoKt34xY1b"
}
signInCartIn(paymentInfo).then(function(result) {
// Read result of the Cloud Function.
}).catch(function(error) {
// Getting the Error details.
var code = error.code;
var message = error.message;
var details = error.details;
console.log(message)
// ...
})
}
I keep getting this error when I call the function
Unhandled error Error: Query.once failed: First argument must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".
what is causing the error and how can I fix it?
Upvotes: 1
Views: 585
Reputation: 3067
What seems to be value
is not really value
.
There are hidden characters in there, a \u200c
and a \u200b
.
Looks like a nasty copy-paste. Delete it and type it yourself.
const yourValue = 'value';
const realValue = 'value';
const yourCharCodes = yourValue.split('').map(c => c.charCodeAt(0)).join(',');
const realCharCodes = realValue.split('').map(c => c.charCodeAt(0)).join(',');
console.log('yourCharCodes:', yourCharCodes);
console.log('realCharCodes:', realCharCodes);
Upvotes: 2