Umb*_*ent 5 javascript firebase-authentication google-cloud-functions
我想知道 Firebase Cloud Functions 本身是否具有可调用函数,例如:
exports.myCallableFunction = functions.https.onCall((data, context) => {
//...
});
Run Code Online (Sandbox Code Playgroud)
本身是安全的,或者如果我需要在其中实现一些代码以确保只有经过身份验证的用户调用它们才能从中获取某些内容。根据我的理解,它是通过 API 端点调用的,所以我有点担心每个人都能够调用它。
如果需要实现某些逻辑,什么逻辑可以确保它是安全的?
如果您希望只有经过身份验证的用户才能调用您的函数,那么可调用函数本身在这方面并不“安全”。您将需要添加代码以确保用户已通过身份验证,然后决定在未通过身份验证时要发送的内容。
exports.myCallableFunction = functions.https.onCall((data, context) => {
if (!context.auth) {
throw new functions.https.HttpsError("unauthenticated", "You must be authenticated");
}
// continue here if they are auth'd
});
Run Code Online (Sandbox Code Playgroud)