firebase-tools getaddrinfo ENOTFOUND metadata.google.internal
Asked Answered
S

3

19

I'm getting this error in my terminal:

@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: \"Failed to parse 
access token response: Error: Error while making request: getaddrinfo 
ENOTFOUND metadata.google.internal metadata.google.internal:80. Error 
code: ENOTFOUND\"."}`

when using firebase-tools. This is the simple node script I'm trying to run.

const admin = require("firebase-admin");

const firebase = admin.initializeApp({
  apiKey: "MY_API_KEY",
  authDomain: "APP_ID.firebaseapp.com",
  databaseURL: `https://DATABASE_URL.firebaseio.com`,
  projectId: "APP_ID"
});

const snap = firebase
  .database()
  .ref("REF")
  .child("ID")
  .once("value");
console.log(snap);

Firebase tools version: 5.0.1

I've tried uninstalling and reinstalling, logging in and out of firebase-tools with firebase login / firebase-logout

Saidee answered 9/10, 2018 at 14:30 Comment(1)
admin.credential.cert(account) works fine. I'd still like to find out why this doesn't thoughSaidee
W
26

the configuration has the wrong structure and lacks fields ...

admin.initializeApp({
    databaseURL: 'https://<DATABASE_NAME>.firebaseio.com',
    credential: admin.credential.cert({
        projectId: '<PROJECT_ID>',
        clientEmail: 'foo@<PROJECT_ID>.iam.gserviceaccount.com',
        privateKey: '-----BEGIN PRIVATE KEY-----\n<KEY>\n-----END PRIVATE KEY-----\n'
    })
});

you cannot just use the "web" configuration to access the Firebase Admin SDK.

because if this would be possible, the private key would be exposed to the public.

see the documentation.

Wareroom answered 9/10, 2018 at 14:42 Comment(2)
Not working, using service_account_id ??? firebase.google.com/docs/auth/admin/…Leopardi
Confirm. service_account_id and databaseUrl are not required for managing users via Firebase Admin SDK.Indecorum
F
1

I solved it simply by running :

firebase login

I also have this error when I don't have an internet connection.

Farmhand answered 22/7, 2020 at 19:53 Comment(1)
wow, you're right! must have been something off with my network adapter & my server. i had internet connection but restarting my computer fixed it!Jacklight
A
1

For those looking to initialise firebase admin SDK on local machine.

  1. Start firbase emulator firebase emulators:start
  2. Run export FIREBASE_AUTH_EMULATOR_HOST="127.0.0.1:9099" to export emulator host
  3. Initialise in code initializeApp({ projectId: 'enter-your-project-id' })
Armitage answered 18/1 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.