本地Firebase模拟器-可调用函数无法访问实时数据库

时间:2020-05-30 15:32:19

标签: node.js firebase firebase-realtime-database google-cloud-functions firebase-admin

我创建了一个可调用函数,该函数将一些值存储到实时数据库中。当我将功能推送到Firebase服务器时,一切正常。

对于开发,我想使用本地仿真器,但是每当我调用将值保存到实时数据库的函数时,它都将失效。

注意:如果我创建了一个将值保存到Firestore的函数,则效果很好

错误

10:05:52
I
function[testFirebase]
Beginning execution of "testFirebase"
10:05:52
I
function[testFirebase]
Finished "testFirebase" in ~1s
10:05:53
I
function[testFirebase]
Beginning execution of "testFirebase"
10:05:54
I
function[testFirebase]
Finished "testFirebase" in ~1s
10:06:40
I
function[testRealtimeDb]
Beginning execution of "testRealtimeDb"
10:06:40
I
function[testRealtimeDb]
Finished "testRealtimeDb" in ~1s
10:06:40
I
function[testRealtimeDb]
Beginning execution of "testRealtimeDb"
10:06:41
I
function[testRealtimeDb]
[2020-05-30T15:06:41.036Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."} 
10:06:41
I
function[testRealtimeDb]
[2020-05-30T15:06:41.144Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."} 
10:06:41
I
function[testRealtimeDb]
[2020-05-30T15:06:41.247Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."} 
10:06:41
I
function[testRealtimeDb]
[2020-05-30T15:06:41.872Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."} 
10:06:42
I
function[testRealtimeDb]
[2020-05-30T15:06:42.406Z]  @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."} 

功能定义

// Function that saves to realtime db
functions.https.onCall((async (data, context) => {
  await admin.database().ref('TEST_PROPERTY').set(data)
  return data;
}));

// Function that saves to firestore - works locally and in server
functions.https.onCall((async (data, context) => {
  await admin.firestore().doc('TEST_PROPERTY').set(data)
  return data;
}));

Firebase管理员初始化(使用打字稿)

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'

admin.initializeApp()

0 个答案:

没有答案