gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:12:31 24 4
gpt4 key购买 nike

我试图弄清楚为什么我的 firestore 函数总是返回 null。这是我的 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!")
})

});

这是我的 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;
}
});
}

有人可以告诉我我做错了什么吗?

最佳答案

根据这个doc

如果返回的是带有键和值的JS对象,我想在这种情况下,getData()返回Map对象。

我认为应该使用 task.getResult().getData().toString() 方法来转换它(而不是 (String) task.getResult().getData() ;)

我希望抛出异常,但也许您已经在此处未发布的代码的其他部分中捕获了它。

希望这对您有帮助。

关于java - 为什么我的 firestore 函数向我的应用程序返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59154999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com