【发布时间】:2019-09-29 13:29:19
【问题描述】:
我尝试从本地项目中调用我的测试函数。
但是当我打电话时,我总是遇到 401 错误。我不知道这里有什么问题,在前端我有带有 api 密钥的初始化应用程序,在 firebase 函数中我有admin.credential.applicationDefault();
我试图通过admin.credential.cer(apiConfig),但这无济于事。
我还有环境变量GOOGLE_APPLICATION_CREDENTIALS,带有我的配置的路径。
依赖关系
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"firebase-functions-test": "^0.1.6",
我的功能
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: "https://plan-list.firebaseio.com"
});
exports.createInviteUser = functions.https.onCall( (data, context)=> {
return data;
});
前端函数请求
createInviteUser(email: string) {
let inviteFunction = firebase.functions().httpsCallable('createInviteUser');
inviteFunction(email)
.then((result) => {
// Read result of the Cloud Function.
console.log(result);
})
.catch(err=>{
console.log(err)
});
}
另外,我如何看到我拥有所有必需的标题
12:54:58.063 PM
createInviteUser
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
12:55:36.257 PM
createInviteUser
Function execution started
12:55:36.257 PM
createInviteUser
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:55:36.271 PM
createInviteUser
Function execution took 15 ms, finished with status code: 204
12:55:36.573 PM
createInviteUser
Function execution started
12:55:36.573 PM
createInviteUser
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:55:36.951 PM
createInviteUser
Function execution took 379 ms, finished with status code: 401
【问题讨论】:
-
您使用的是 Node 10 版吗?如果是这样,请参阅this open issue。您需要降级到 Node v8。
-
@BobSnyder ohhh goood,两天让我大吃一惊,非常感谢!
-
以后,如果您有关于 Firebase CLI 的错误报告,请发布到项目 GitHub 而不是 Stack Overflow,或者向 Firebase 支持提交错误请求。 Stack Overflow 用于编程问题。
标签: firebase firebase-authentication google-cloud-firestore google-cloud-functions