简体   繁体   English

为什么我的 firestore 函数向我的应用程序返回 null?

[英]Why does my firestore function return null to my app?

I'm trying to figure aout, why my firestore function is always returning null.我想弄清楚,为什么我的 firestore 函数总是返回 null。 Here is my firestore function:这是我的 Firestore 功能:

exports.isUserOnListFunction = functions.https.onCall(async (data, context) => {
    const userID = context.auth.uid;
    const userEmail = context.auth.token.email;
    const atIndex = userEmail.indexOf('@');
    const dotIndex = userEmail.indexOf('.');
    var userName = userEmail.slice(0, dotIndex);
    var userSurname = userEmail.slice(dotIndex+1, atIndex);
    userName = capitalizeFirstLetter(userName);
    userSurname = capitalizeFirstLetter(userSurname);
    return db.collection('allowed_users')
        .where("name", "==", userName)
        .where("surname", "==", userSurname)
        .get().then(snap => {
            if (!snap.empty) {
                db.collection("users").doc(userID).update({
                    onList: true
                });
                return {onList : true};
            }
        }).catch(()=>{
            console.log("Some error!")
        })

});

and here is my android (java) function calling firestore function:这是我的 android (java) 函数调用 firestore 函数:

    private Task<String> isUserOnList(){
    return mFunctions
            .getHttpsCallable("isUserOnListFunction")
            .call()
            .continueWith(new Continuation<HttpsCallableResult, String>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                    String result = (String) task.getResult().getData();
                    System.out.println(result);
                    return result;
                 }
            });
}

Could someone please tell me what im doing wrong?有人可以告诉我我做错了什么吗?

According to this doc根据这个文档

If returned is JS object with keys and values, which I suppose it is in this situation, getData() returns Map object.如果返回的是带有键和值的 JS 对象,我想是在这种情况下,getData() 返回 Map 对象。

I think task.getResult().getData().toString() method should be used to convert it (instead of (String) task.getResult().getData(); )我认为task.getResult().getData().toString()方法应该用来转换它(而不是(String) task.getResult().getData();

I would expect exception thrown, but maybe you have caught it in other parts of code not posted here.我希望抛出异常,但也许您已经在此处未发布的其他代码部分中捕获了它。

Hope this will helps you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM