Firebase functions.httpsCallable (...). Тогда это не функция - PullRequest
0 голосов
/ 08 января 2020

Я пытаюсь использовать функцию, которую я сделал. Так что в моем клиенте я делаю это:

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
            }
        })

и в основном я получаю ошибку, functions.httpsCallable(...).then is not a function. Я действительно не понимаю, и я не нахожу никакой документации, как сделать вызов функции на клиенте в другой версии.

Это мой сервер


// 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 Ответ

1 голос
/ 08 января 2020

HttpsCallable сам по себе является функцией, которую можно вызывать с параметрами, вам нужно добавить туда еще ():

const getSelf = functions.httpsCallable('getSelf');
getSelf({}).then(...);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...