Reputation:
I'm trying to figure aout, why my firestore function is always returning null. Here is my firestore function:
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:
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?
Upvotes: 0
Views: 204
Reputation: 4272
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.
I think task.getResult().getData().toString()
method should be used to convert it (instead of (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.
Upvotes: 2