【发布时间】:2020-09-26 12:12:18
【问题描述】:
我在 firebase 云函数中创建了一个可调用函数,但每当我调用它时都会出现此错误
未捕获(承诺中)FirebaseError:消息:为用户订阅 FCM 时出现问题:请求缺少所需的身份验证凭据。预期的 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。见https://developers.google.com/identity/sign-in/web/devconsole-project。 (消息/令牌订阅失败)
我已经看到了如何在 firebase 中调用可调用函数的示例 https://firebase.google.com/docs/functions/callable#call_the_function 但它不起作用
我也试过了,但仍然遇到同样的错误 https://cloud.google.com/functions/docs/securing/managing-access-iam#allowing_unauthenticated_function_invocation
这是我调用函数的方式
const invite = firebase.functions().httpsCallable('inviteUser');
... // some other code
invite({ email, organization: data.name })
后端代码
export const inviteUser = functions.https.onCall(({ email, organization }) => {
try {
sendMail(email, organization);
return 'success'
} catch(e) {
return e;
}
})
注意我正在使用打字稿
【问题讨论】:
-
我也使用 firebase auth 登录了用户
-
您使用的是来自
admin.initializeApp(functions.config().firebase);的 Firebase 实例吗?您看到的错误表明您没有提供使用任何身份验证凭据创建的 firebase 实例。 -
是的,我在 firebase 函数中做到了这一点,错误发生在前端,我实际上并没有使用任何 firebase 管理函数,所以我怀疑这种情况
-
我没有使用 firebase fcm 那么为什么我会出错呢?
标签: javascript typescript firebase google-cloud-functions