【问题标题】:How to implement a firebase cloud functions in ionic?如何在 ionic 中实现 firebase 云功能?
【发布时间】:2019-03-14 14:26:06
【问题描述】:

我想用 firebase 函数实现一个函数,但问题是在 firebase 面板中它永远不会反映正在做某事。

这是我的函数代码,想法是从具有特定 id 的特定文档中获取所有数据。

exports.identifyusers=functions.https.onRequest((req, res) => {
    
    var db = admin.firestore();
    const key=req.query.key;
    
   return db.collection("usuariosdinny").doc(key).get().then(snapshot => {
   
    console.log("Correcto")

    }).catch(reason => {
        res.send(reason)
    })
});

这是我调用函数时的部分:(这部分是一个正确的身份验证过程,用户我得到了 id 并将这个 id 发送给函数)

this.afAuth.auth.signInWithEmailAndPassword(userst.email,userst.password)
        .then(res=> 
          {
            
          console.log(this.afAuth.auth.currentUser.uid);
          var tipo= firebase.functions().httpsCallable('identifyusers').arguments(this.afAuth.auth.currentUser.uid);
          console.log(tipo);

          if(tipo=="Cliente Dinny")
          {
            console.log("Es un cliente");
          }
          else{
            console.log("No tiene permiso para")
          }         
          }
        
          
          //this.navCtrl.push(TabsControllerPage)&& loader.dismiss())
        ).catch(reject =>alert.present() && loader.dismiss());
      }).catch(reject=>loader.dismiss());

感谢您的帮助。

【问题讨论】:

    标签: typescript firebase ionic-framework firebase-authentication google-cloud-functions


    【解决方案1】:

    您的客户端代码正在尝试调用“可调用”函数:

    firebase.functions().httpsCallable('identifyusers')
    

    但是你的函数被定义为 HTTP 类型的函数:

    exports.identifyusers=functions.https.onRequest(...)
    

    如果要调用可调用函数,则必须编写可调用函数。 Read the documentation for callable functions 了解如何做到这一点。

    exports.identifyusers = functions.https.onCall(...)
    

    【讨论】:

    • 当我用这个选项实现功能时,我无法部署
    • 听起来你现在有一个不同的问题要问一个新问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2018-08-30
    • 2020-06-09
    • 2019-06-22
    • 2017-10-05
    • 1970-01-01
    • 2021-04-26
    相关资源
    最近更新 更多