firebase-functions: FIREBASE WARNING: Provided authentication credentials for the app named "[DEFAULT]" are invalid. This usually indicates your app was not initialized correctly. Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.
Version info
firebase-functions: 0.7.3
firebase-tools: 3.16.0
firebase-admin: 5.5.1
Test case
var defaultApp = admin.initializeApp(functions.config().firebase);
Steps to reproduce
var functions = require('firebase-functions');
const admin = require('firebase-admin');
var defaultApp = admin.initializeApp(functions.config().firebase);
defaultApp.database().ref(`/users/${event.params.userId}/unreadNotificationCount`).once("value").then(unreadNotificationCountRef => {
});
Were you able to successfully deploy your functions?
YES Function is running on Firebase Cloud but its failing with following error message
FIREBASE WARNING: Provided authentication credentials for the app named “[DEFAULT]” are invalid. This usually indicates your app was not initialized correctly. Make sure the “credential” property provided to initializeApp() is authorized to access the specified “databaseURL” and is from the correct project.
console.log(" Firebase Initialize ", functions.config().firebase);
{ databaseURL: 'https://xxx.firebaseio.com',
storageBucket: 'xxx.appspot.com',
apiKey: '123123',
authDomain: 'xxx.firebaseapp.com',
projectId: 'xxx',
credential: ApplicationDefaultCredential { credential_: MetadataServiceCredential {} } }
I also tried with service account but still same error
var serviceAccount = require('./serviceaccount.json');
var defaultApp = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://xxxx.firebaseio.com"
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 31 (5 by maintainers)
Commits related to this issue
- Add support for Crashlytics-triggered functions (#147) — committed to Byeol/firebase-functions by laurenzlong 7 years ago
For everyone else who sees this issue in the future. If you are seeing this in DEPLOYED functions, try:
Sorry for this hacky workaround. We are pushing out a server-side fix in the next few weeks, so this won’t occur any longer, but unfortunate right now it’s affecting a small percentage of projects.
If the above workaround doesn’t resolve the issue, please file a support ticket
UPDATE : The below did not solve this. It did remove the error although db write/read was not working/ignored/silently failed
UPDATE2 : Simply removing the credential field solved this for me. I would however like to use a service account but removing it solved this for me.
For what its worth I noticed I could provide a custom name when I created the database. Using the
project-id
and not thedatabase-name
solved this for me, even though documentation uses thedatabase-name
@laurenzlong - I just tried your suggestion but I’m still getting the same warning message throughout my logs. I’ve been working on this for weeks and have a support ticket open but still no resolution.
I’m getting the same error and need help. I’ve filed a support ticket.
I am also getting the same error using firebase-admin and serviceAccount. How can i fix this?
@laurenzlong Hi, I’m trying to update Node 8 -> Node 10 and always having the error
I have already tried the steps which you suggested, also check my service accounts and variables, but without any results.
Even if I deploy only 1 function on NodeJS 10, then it’s started giving me the error. Also strange thing that it’s working fine on our
dev
project and it’s happening only on theproduction
project.Could you help or suggest any ideas where we can look for?
To whoever see this message and he/she is just using firebase for their database with the use of a key. The depedency between your service account and the generated key is messed up for some reason, (some change or some deletion etc), and a probable way to solve this quickly is to go to the service accounts, create a new one if needed, and generate a new key. Understandably that doesn’t cover all the cases, but it is a very usual case I believe.
Faced the same issue, solved it as in update2 from @Portur by simply removing credentials from initializing and putting just:
admin.initializeApp()
I have the same problem:
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: "getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80".”}
Note: my cloud functions doesn’t make any external calls
Since I implemented unit tests in online mode for Cloud Functions v1.0, using the test initialization as documented in my
test.online.js
:so my
firebase-admin
initialization inindex.js
looks like the “Migrate to v1.0” documentation:I temporarily solved initializing admin inside my
test.online.js
withcredential
anddatabaseUrl
like the reference documentation:and modifying my functions
index.js
like this:So when I run online tests, admin is first initialized correctly by
test.online.js
andindex.js
doesn’t create a new firebase app. My offline and online tests are working now, and I can deploy without any problems.Could it be that a service was down today? I had this error an hour ago but now it’s gone again.
Facing the same issue. And funny thing is they charge you for this error. Any luck for @clorieanne @jenkinshouse @reddy-v
Also have the same problem. Has someone solved this issue? 😃