firebase-functions: 0.7.3
firebase-tools: 3.16.0
firebase-admin: 5.5.1
var defaultApp = admin.initializeApp(functions.config().firebase);
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 => {
});
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"
});
Hi @Vani-gurnani could you follow Thomas' instructions in https://github.com/firebase/firebase-functions/issues/134#issuecomment-350377545 to file a support ticket so we can dig into your specific project more?
I am also getting the same error using firebase-admin and serviceAccount. How can i fix this?
I'm getting the same error and need help. I've filed a support ticket.
For everyone else who sees this issue in the future. If you are seeing this in DEPLOYED functions, try:
1) deleting all your functions
2) disable cloud functions API at console.cloud.google.com/apis/api/cloudfunctions.googleapis.com
3) re-enable API
4) re-deploy function
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
@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.
@jenkinshouse what's your support ticket ID?
Also have the same problem. Has someone solved this issue? :)
@clorieanne See https://github.com/firebase/firebase-functions/issues/147#issuecomment-360543445
Facing the same issue. And funny thing is they charge you for this error. Any luck for @clorieanne @jenkinshouse @reddy-v
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 right now.
Same issue here
Same issue over here.
Got the same issue today, but @laurenzlong proposed solution seems to have done the trick.
@laurenzlong the hack didn't solve the issue
Same here...
fwiw, I got this warning when I specified the wrong databaseURL in the admin.initializeApp call
Me,too...
hi @all
When i run admin section of app then i face this warning . @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: \"getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80\"."}. If anyone fixed this problem then please share it.
Same problem with the latest version of firebase libraries:
This was frustrating me for a full day.... its fixed now after a few things that I'll share;
updated firebase-tools to 3.18.4
sudo npm uninstall -g firebase-tools && sudo npm i -g firebase-tools
suffered some ridiculous permissions issue where the log files that where generated from firebase serve were not going to the local folder but to the root folder.
-- not sure how this was solved firebase use i think
created a new service account and specified the following roles during creation
-- DataStore -> Cloud DataStore Owner
-- Project -> Project Owner
went back to using the following init lines
const serviceAccount = require('./../service-account.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://#####.firebaseio.com"
});
and finally... and this may very well have been the problem all along.... I fixed a line of code that was part of the Real Time Database API and not the Firestore API. It wasn't glaringly obvious either so it might trip up others. Could explain the permission errors.
a final observation... when testing locally with firebase serve.. i encounter some caching of execution or results that gives me seemingly unrelated errors about socket closures. It seems that when i remove the output *.log files created and hit refresh in the browser the issue corrects itself. Sounds strange now that I type it out.
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:
const test = require('firebase-functions-test')( {
projectId: '<project-id>',
databaseURL: 'https://<project-id>.firebaseio.com'
}, './service_accounts/service-account-key.json');
so my firebase-admin initialization in index.js looks like the "Migrate to v1.0" documentation:
const admin = require('firebase-admin');
admin.initializeApp();
I temporarily solved initializing admin inside my test.online.js with credential and databaseUrl like the reference documentation:
const serviceAccount = require('./../service-account.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://<project-id>.firebaseio.com"
});
and modifying my functions index.js like this:
const admin = require('firebase-admin');
try {
admin.app();
} catch(e) {
admin.initializeApp();
}
So when I run online tests, admin is first initialized correctly by test.online.js and index.js doesn't create a new firebase app.
My offline and online tests are working now, and I can deploy without any problems.
For everyone else who sees this issue in the future. If you are seeing this in DEPLOYED functions, try:
- deleting all your functions
- disable cloud functions API at console.cloud.google.com/apis/api/cloudfunctions.googleapis.com
- re-enable API
- re-deploy function
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
i have tried your solution but still getting the same issue. need your assistance.
For what its worth I noticed I could provide a custom name when I created the database.
Using the project-id and not the database-name solved this for me, even though documentation uses the database-name
var admin = require('firebase-admin');
var serviceAccount = require('path/to/serviceAccountKey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://<PROJECT-ID >.firebaseio.com'
});
Can you try adding projectId as well into initializeApp()?
Also can you check your Functions logs for more information? They may contain credential errors from the service account.
Again, if these issues are still persisting after https://github.com/firebase/firebase-functions/issues/147#issuecomment-360543445, please file a support ticket.
Faced the same issue, solved it as in update2 from @Portur by simply removing credentials from initializing and putting just:
admin.initializeApp()
Before using this option by @laurenzlong, I used this procedure https://itayhauptman.wordpress.com/2016/10/06/firebase-firebase-warning-provided-authentication-credentials-are-invalid-this-usually-indicates-your-firebaseapp-instance-was-not-initialized-correctly/
For everyone else who sees this issue in the future. If you are seeing this in DEPLOYED functions, try:
- deleting all your functions
- disable cloud functions API at console.cloud.google.com/apis/api/cloudfunctions.googleapis.com
- re-enable API
- re-deploy function
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
@laurenzlong Hi,
I'm trying to update Node 8 -> Node 10 and always having the error
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.
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 the production project.
Could you help or suggest any ideas where we can look for?
Most helpful comment
For everyone else who sees this issue in the future. If you are seeing this in DEPLOYED functions, try:
1) deleting all your functions
2) disable cloud functions API at console.cloud.google.com/apis/api/cloudfunctions.googleapis.com
3) re-enable API
4) re-deploy function
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