1

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('v‌​alue');
 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?

2
  • You probably want to log and return snapshot.val() instead of snapshot (as snapshot itself isnot a JSON object). But that shouldn't be causing the error you get. The once() call looks fine to me. Are you sure that error is coming from this code? Commented Nov 20, 2020 at 0:43
  • @FrankvanPuffelen I thought so too. I have included the client side call to see maybe I'm missing something Commented Nov 20, 2020 at 1:28

1 Answer 1

2

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 = 'v‌​alue';
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);

Sign up to request clarification or add additional context in comments.

3 Comments

Great catch Stratubas. I wish I could upload multiple times. There are indeed two non-visible unicode characters in there (‌ and ​).
where exactly are they located and were you able to find them?
@learner101 I don't have a specific method. I just tried copy-pasting your 'value' in Chrome dev console, to check for === with a "normal" 'value', and two red dots appeared in the text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.