我尝试从本地项目调用测试函数。
但是,每次我打电话时,我都遇到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
答案 0 :(得分:4)
在Node v10中部署功能时会发生此错误。它是由bug in firebase-functions引起的。有一个修复程序,但尚未发布。在此之前,通过更改package.json
文件将其降级到Node v8:
"engines": {
"node": "8"
}