This is how I'm currently checking if user is authenticated within the onCall
function before triggering the logic:
exports.foobar = functions.https.onCall(async (data, context) => {
if (!context.auth) {
throw new functions.https.HttpsError(
'unauthenticated',
'You must be authenticated'
)
}
// Now user is authenticated
}
The problem with it is that even the user is not authenticated (eg some third-party agent) it still counts as a call, hence I will be billed for it.
It opens up a scenario when my app could be a subject of a DDoS attack, and since there is no way to limit my expenses in Google's Firebase console, potentially there is no limit to how big the bill could be.
So, I'd like to know how to protect the endpoint, like if there is a way to limit the function call only to authenticated users, without getting billed for the verification step.