【发布时间】:2020-03-28 00:21:43
【问题描述】:
我想弄清楚为什么我的 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!")
})
});
这是我的调用 firestore 函数的 android (java) 函数:
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;
}
});
}
谁能告诉我我做错了什么?
【问题讨论】:
-
你需要注意
update返回的promise,否则你的函数可能会在工作完成之前提前终止。 -
我做了一些研究,你是 100% 正确的。感谢您的时间! :)
标签: java android promise google-cloud-firestore google-cloud-functions