Dro*_*rop 0 firebase firebase-authentication google-cloud-functions google-cloud-firestore
我尝试从本地项目调用我的测试函数。
但是每次我打电话时,我都会收到 401 错误。我不知道这里有什么麻烦,在前端我有带 api 密钥的 init 应用程序,在我有 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",
Run Code Online (Sandbox Code Playgroud)
我的功能
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;
});
Run Code Online (Sandbox Code Playgroud)
前端功能请求
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)
});
}
Run Code Online (Sandbox Code Playgroud)
另外,我怎么看我有所有必需的标题
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
Run Code Online (Sandbox Code Playgroud)
使用 Node v10 部署函数时会发生此错误。它是由firebase-functions 中的错误引起的。有一个修复程序,但尚未发布。在此之前,请通过更改package.json文件降级到 Node v8 :
"engines": {
"node": "8"
}
Run Code Online (Sandbox Code Playgroud)