Hey guys,
I need to check if some user exists in the "users" table by his UID. This table contains sensitive data, so it is protected and one can't directly "read" any of its records, only the authenticated user related to the specific record can get the data. So I should use a cloud function, since it's being run under a kind of "superuser" and dismiss any access checks in Firestore.
Here is my function code:
exports.checkUserExists = functions.https.onCall( (data) => {
const {uid} = data;
admin.firestore().collection("users").doc(uid).get().then(function (doc) {
if (doc.exists) {
console.log('Found');
return 'Found';
} else {
console.log('Not found');
return 'Not found';
}
}).catch(function (err) {
console.log(err);
return 'Error: ' + err;
});
});
When I run this function and make an alert (informational dialog) with the result - it displays nothing. The raw result body is null.
It seems the code doesn't wait for Firestore get() request to be executed so the function immediately returns nothing... Any thoughts on that?