问题描述
我尝试从本地项目调用测试函数.
I try to call my test function from local project.
但是,每次我打电话时,我都遇到401错误.我不知道这里有什么麻烦,在前端我有带有api键的初始化应用程序,在firebase函数中我有admin.credential.applicationDefault()
;
我试图通过admin.credential.cer(apiConfig)
,但这无济于事.
But all time when i call, i take 401 error. I don't know what trouble here, in front end i have init app with api key, in firebase function i have admin.credential.applicationDefault()
;
I tried to pass admin.credential.cer(apiConfig)
, but this don't help to.
我也有环境变量GOOGLE_APPLICATION_CREDENTIALS
,其中包含我的配置路径.
I also have Environment variable GOOGLE_APPLICATION_CREDENTIALS
, with path to my config.
依赖项
"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)
});
}
另外,我怎么看我拥有所有必需的标题
Also, how i see i have all required headers
从控制台获取日志
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 v10部署功能时会发生此错误.这是由于 firebase函数中的错误引起的.有一个修复程序,但尚未发布.在此之前,通过更改您的package.json
文件降级到Node v8:
This error occurs when functions are deployed with Node v10. It is caused by a bug in firebase-functions. There is a fix but it is not yet released. Until it is, downgrade to Node v8 by changing your package.json
file:
"engines": {
"node": "8"
}