1

I am trying to use a function I made. So in my client I am doing this:

const functions = firebase.app().functions("europe-west1");

        functions.httpsCallable('getSelf').then(res => {
            console.log(res);
            //stuff
        }).catch(e => {
            console.log(e);
            switch (e.code) {
                //stuff
            }
        })

and basically I get the error that functions.httpsCallable(...).then is not a function. I dont really get it and I do not find any documentation how to make a function call on the client on a different version.

This is my serverside


// Gets things like adminlevel, profilepic etc
exports.getSelf = functions.region("europe-west1").https.onCall((data, context) => {
  // Checking that the user is authenticated.
  if (!context.auth) 
    // Throwing an HttpsError so that the client gets the error details.
    throw new functions.https.HttpsError('unauthorized', 'The function must be called ' +
        'while authenticated.');

  return db.collection("userInformation").doc(context.auth.uid).then(user => {
    if(!user)
      new functions.https.HttpsError('not-found', 'The user was not found');
    //returns needing values
    return {
      profilePicture: user.profilePicture,
      adminLevel: user.adminLevel,
      stripeAccountId: user.stripeAccountId,
      stripeCustomerId: user.stripeCustomerId,
      type: user.type
    }
  })
});

1 Answer 1

4

The HttpsCallable is itself a function that can be called with parameters, you need to add another () in there:

const getSelf = functions.httpsCallable('getSelf');
getSelf({}).then(...);
Sign up to request clarification or add additional context in comments.

2 Comments

So that fixed my "not a function" error. Now I get an internal error.
Looks like return db.collection("userInformation").doc(context.auth.uid) needs to be return db.collection("userInformation").doc(context.auth.uid).get() as well.

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.