Error: 16 UNAUTHENTICATED: Failed to retrieve auth metadata with error: Could not refresh access token

The complete error is as follows:

Unhandled error Error: 16 UNAUTHENTICATED: Failed to retrieve auth metadata with error: Could not refresh access token: Unsuccessful response status code. Request failed with status code 500
at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:327:49)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181)
at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Caused by: Error
at Query._get (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1449:23)
at Query.get (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:1438:21)
at Object.getTeacherDataWithFilters (/workspace/lib/teachers/methods.js:168:81)
at /workspace/lib/teachers/callable.js:22:36
at func (/workspace/node_modules/firebase-functions/lib/providers/https.js:273:32)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 16,
details: 'Failed to retrieve auth metadata with error: Could not refresh access token: Unsuccessful response status code. Request failed with status code 500',
metadata: Metadata { internalRepr: Map {}, options: {} }

I recently deployed to the firebase functions and now I am getting this error. I dont know what has happened and I could not find anything specific to this


I have figured out the actual reason and that's why I am answering my own question. The reason why I was getting this error is that the default service account attached to this project which is mostly like <project-ID>@appspot.gserviceaccount.com was disabled. After enabling, everything worked fine.


I faced the same error, it was a authentication issue due to credentials. Below command fixed it for me.

 gcloud auth application-default login

I got below output after running this command.

Credentials saved to file: [/Users/username/.config/gcloud/application_default_credentials.json]. These credentials will be used by any library that requests Application Default Credentials (ADC).

Official Document for Reference