firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Firebase CLI Login Failed - Error on firebase login

Open alihamza0173 opened this issue 1 year ago • 24 comments

[REQUIRED] Environment info

Firebase CLI Version: 13.33.0 Node.js Version: v20.10.0 Linux 6.12.13-amd64

[REQUIRED] Test case

Download firebase-tools or firebase-cli and authenticate from the terminal

[REQUIRED] Steps to reproduce

Execute firebase login, firebase login --reauth, firebase login --no-localhost and basically all versions of authentication available. Including ones with login:ci

[REQUIRED] Expected behavior

The authentication should complete successfully within the terminal

[REQUIRED] Actual behavior

  • The CLI opens a browser window for authentication.
  • The browser displays the following error message:
Oops!
Firebase CLI Login Failed
The Firebase CLI login request was rejected or an error occurred. Please run firebase login again or contact support if you continue to have difficulty logging in.

Meanwhile, the terminal outputs the following logs:

Firebase optionally collects CLI and Emulator Suite usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.
 
? Allow Firebase to collect CLI and Emulator Suite usage and error reporting 
information? Yes
i  To change your data collection preference at any time, run `firebase logout` and log in again. 

Visit this URL on this device to log in:
https://accounts.google.com/o/oauth2/auth?client_id=563584335869-fgrhgmd47bqnekij5i8b5pr03ho849e6.apps.googleusercontent.com&scope=email%20openid%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloudplatformprojects.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Ffirebase%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&response_type=code&state=842300911&redirect_uri=http%3A%2F%2Flocalhost%3A9005

Waiting for authentication...
[2025-03-10T15:31:09.297Z] >>> [apiv2][query] POST https://accounts.google.com/o/oauth2/token [none]
[2025-03-10T15:31:09.302Z] >>> [apiv2][body] POST https://accounts.google.com/o/oauth2/token [omitted]
[2025-03-10T15:31:09.818Z] *** [apiv2] error from fetch(https://accounts.google.com/o/oauth2/token, {"headers":{},"method":"POST","body":{"_overheadLength":543,"_valueLength":208,"_valuesToMeasure":[],"writable":false,"readable":true,"dataSize":0,"maxDataSize":2097152,"pauseStreams":true,"_released":true,"_streams":[],"_currentStream":null,"_insideLoop":false,"_pendingNext":false,"_boundary":"--------------------------774456112272132751061107","_events":{},"_eventsCount":1}}): FetchError: request to https://accounts.google.com/o/oauth2/token failed, reason: 
[2025-03-10T15:31:09.820Z] Token Fetch Error: FirebaseError: Failed to make request to https://accounts.google.com/o/oauth2/token
    at RetryOperation._fn (/home/darkreaper/.nvm/versions/node/v20.10.0/lib/node_modules/firebase-tools/lib/apiv2.js:261:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci
[2025-03-10T15:31:09.842Z] >>> [apiv2][query] POST https://auth.firebase.tools/attest [none]
[2025-03-10T15:31:09.843Z] >>> [apiv2][body] POST https://auth.firebase.tools/attest {"session_id":"0488bc1a-09e8-4374-bc7d-ea8f46f10975"}
[2025-03-10T15:31:10.856Z] <<< [apiv2][status] POST https://auth.firebase.tools/attest 200
[2025-03-10T15:31:10.857Z] <<< [apiv2][body] POST https://auth.firebase.tools/attest {"token":"jEMefqcNhsrJC0LEiByNS8ZrFqAjvarPBWTTsJuQeu0"}

To sign in to the Firebase CLI:

1. Take note of your session ID:

   0488B

2. Visit the URL below on any device and follow the instructions to get your code:

   https://auth.firebase.tools/login?code_challenge=1N6ynEeq4AgfXbKNiDvos3Lmn4m1kIJzQl0WB9bsQr8&session=0488bc1a-09e8-4374-bc7d-ea8f46f10975&attest=jEMefqcNhsrJC0LEiByNS8ZrFqAjvarPBWTTsJuQeu0

3. Paste or enter the authorization code below once you have it:

? Enter authorization code: 


alihamza0173 avatar Mar 10 '25 15:03 alihamza0173

Hey @alihamza0173, sorry to hear you're encountering this issue. Usually, we see this occur when there is a Firewall or proxy misconfiguration that is blocking the network request. To rule out the possibility that this is a network issue, could you try connecting to a different network or temporarily disabling VPN, Firewall, and proxy you may have?

Also, try running curl -X POST -I https://accounts.google.com/o/oauth2/token to see if you'd be able to make a request to that endpoint.

aalej avatar Mar 11 '25 18:03 aalej

hi @aalej I was connected to my regular WiFi and was not using any VPN, proxy, or firewall while facing this issue.

I ran the suggested API request, and here is the result:

curl -X POST -I https://accounts.google.com/o/oauth2/token  
HTTP/2 400  
content-type: application/json; charset=utf-8  
vary: X-Origin  
vary: Referer  
vary: Origin,Accept-Encoding  
date: Wed, 12 Mar 2025 00:50:42 GMT  
server: scaffolding on HTTPServer2  
x-xss-protection: 0  
x-frame-options: SAMEORIGIN  
x-content-type-options: nosniff  
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000  
accept-ranges: none  

Furthermore, I had attempted logging in several times over two days, but the problem continued. Yet, I just attempted it again today, and although it failed twice, it did manage to connect successfully on the third try.

I was connected to the same network as yesterday, so there would not appear to have been any change in the network that would have influenced the result.

Please let me know if you require any additional information. Thanks!

alihamza0173 avatar Mar 12 '25 01:03 alihamza0173

Shifting to a mobile data network works for me.

yodit93 avatar Nov 17 '25 09:11 yodit93

Shifting to a mobile data network works for me.

@yodit93, Yes, changing the network worked for me as well. I didn’t switch to mobile data, but when I connected through Cloudflare’s 1.1.1.1, the login succeeded.

alihamza0173 avatar Nov 18 '25 15:11 alihamza0173

I'm having the same error using a linux environment on a chromebook using cloudflare DNS (1.1.1.1)

$ uname -a Linux penguin 6.6.99-09000-gd3ae1caecf39 #1 SMP PREEMPT_DYNAMIC Thu, 27 Nov 2025 21:00:42 -0800 x86_64 GNU/Linux $ nodejs --version v22.23.0 $ firebase --version 15.22.0

Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Error: Unable to authenticate using the provided code. Please try again.

Having trouble? Try firebase [command] --help

Using the --debug flag

[2026-06-19T04:49:46.932Z] >>> [apiv2][query] POST https://accounts.google.com/o/oauth2/token [none]
[2026-06-19T04:49:46.936Z] >>> [apiv2][body] POST https://accounts.google.com/o/oauth2/token [omitted]
[2026-06-19T04:49:47.276Z] Token Fetch Error: FirebaseError: FetchError: Invalid response body while trying to fetch https://accounts.google.com/o/oauth2/token: Premature close
    at RetryOperation._fn (/usr/lib/node_modules/firebase-tools/lib/apiv2.js:317:88)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Error: Unable to authenticate using the provided code. Please try again.

-Alvaro

alsotoes avatar Jun 19 '26 04:06 alsotoes

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error.

This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs:

require('http').globalAgent.keepAlive = false;
require('https').globalAgent.keepAlive = false;

Then run the CLI with it preloaded:

NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login

Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

harryn0502 avatar Jun 19 '26 08:06 harryn0502

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error.

This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs:

require('http').globalAgent.keepAlive = false; require('https').globalAgent.keepAlive = false; Then run the CLI with it preloaded:

NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

try switching from node 24 to 22, helped for me

jmisilo avatar Jun 19 '26 11:06 jmisilo

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error.

This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs:

require('http').globalAgent.keepAlive = false; require('https').globalAgent.keepAlive = false; Then run the CLI with it preloaded:

NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

A Windows equivalent that worked for me:

$env:NODE_OPTIONS = "--require .\no-keepalive.cjs"
firebase login

brunyeestudio avatar Jun 19 '26 13:06 brunyeestudio

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error. This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs: require('http').globalAgent.keepAlive = false; require('https').globalAgent.keepAlive = false; Then run the CLI with it preloaded: NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

try switching from node 24 to 22, helped for me

I believe this works because of this issue raised here against Node.js: https://github.com/nodejs/node/issues/63989 There is also this Firebase CLI issue here: https://github.com/firebase/firebase-tools/issues/10681

The solution is to downgrade NodeJS to 24.16.0 if using v24 or to downgrade to 22.22.0 if using v22. I can confirm that NodeJS v22.22.0 works fine.

benbrunyee avatar Jun 19 '26 16:06 benbrunyee

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error. This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs: require('http').globalAgent.keepAlive = false; require('https').globalAgent.keepAlive = false; Then run the CLI with it preloaded: NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

try switching from node 24 to 22, helped for me

I believe this works because of this issue raised here against Node.js: nodejs/node#63989 There is also this Firebase CLI issue here: #10681

The solution is to downgrade NodeJS to 24.16.0 if using v24 or to downgrade to 22.22.0 if using v22. I can confirm that NodeJS v22.22.0 works fine.

Thank you thank you. You're a life saver!

sanjay51 avatar Jun 20 '26 23:06 sanjay51

Ran into the exact same thing. In my case the Authentication Error: Your credentials are no longer valid message was a total red herring.

When this happens

  • On any command that makes an authenticated request (firebase login, token refresh, deploy, projects:list, etc.) and even mcp that uses firebase-tools internally.
  • On Node 19+ (I am on Node 24)
  • On current firebase-tools, including the latest 15.22.0 (which still pins node-fetch@^2.6.7, so bumping the CLI version does not help)
  • Re-authing via firebase login --reauth does not fix it because brand new credentials fail identically

What's actually happening

The CLI uses a bundled version of node-fetch@2 that terminates the connection early during the token request, triggering a FetchError: Invalid response body … Premature close. The CLI just catches that and spits out a generic auth error.

This happens on Node 19+ because Node changed its global HTTP agent default to keepAlive: true, a connection-reuse behavior node-fetch@2 does not handle reliably.

Quick Workaround

You can force keep-alive off for the execution. Drop this into a file named no-keepalive.cjs:

require('http').globalAgent.keepAlive = false; require('https').globalAgent.keepAlive = false; Then run the CLI with it preloaded:

NODE_OPTIONS="--require ./no-keepalive.cjs" firebase login Login and every other command should work again. To make it stick, you can add that NODE_OPTIONS line to your shell profile (.bashrc or .zshrc).

Real fix

This needs firebase-tools to move off node-fetch@2.

  • Option A: Address the node-fetch@2 keep-alive handling or upgrade to a version that handles it better.
  • Option B: Migrate completely to the native fetch API / undici to resolve it, though it is currently unconfirmed if this fully mitigates the body-stream premature closes.

Bro, you saved hours of my life!

FoKas90 avatar Jun 21 '26 11:06 FoKas90

I downgraded to Node 20 and that fixed it for me. Also I had to delete node from a bunch of places (except homebrew on mac) so that it could point to the right installation. which -a node

brew install node@20
brew unlink node
brew link --overwrite --force node@20

sanjay51 avatar Jun 21 '26 15:06 sanjay51

I downgraded to v22.22 and it fixed it for me. First downgraded to v22.23 but that didn't fix it.

hreward avatar Jun 22 '26 08:06 hreward

Hey folks, I'm reading through the recent comments and I think the issue you're encountering is different from the initial report. I think you're encountering an issue that is similar to #10681 and #10692, whose root cause is this issue on Node.js https://github.com/nodejs/node/issues/63989.

Please downgrade to either Node 22.22.x or Node 24.16.x to workaround this. Also refer to #10692 if you're encountering this issue when using Node.js v24.17.0 or v22.23.0.

aalej avatar Jun 22 '26 10:06 aalej

I downgraded to v22.22 and it fixed it for me. First downgraded to v22.23 but that didn't fix it.

same here. Took lots of my time to fix but a simple downgrade finally worked.

N-Iregi avatar Jun 22 '26 14:06 N-Iregi

Still doesn't work for me, even with Node 22.22.0.

❯ firebase --version 15.22.0

❯ node -v v22.22.0

To sign in to the Firebase CLI:

1. Take note of your session ID:

   24166

2. Visit the URL below on any device and follow the instructions to get your code:

   https://auth.firebase.tools/login?code_challenge=uFlFtkpXkseUzEuXOcmWwiPK-iPqEnM5X-o8VZ5Umo4&session=24166665-939c-4ecb-ba06-56316b835696&attest=srqsjlbSgUDKzOYiUJijsXpr03hu8aOmR0Z9QdK2KgI

3. Paste or enter the authorization code below once you have it:

✔ Enter authorization code: <redacted>
Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

For CI servers and headless environments, generate a new token with firebase login:ci

Error: Unable to authenticate using the provided code. Please try again.

Having trouble? Try firebase [command] --help

kypeli avatar Jun 22 '26 15:06 kypeli

❯ firebase --version 15.22.1

Update: I updated the Firebase CLI version and now I managed to authenticate with Node 22.22.0.

kypeli avatar Jun 23 '26 06:06 kypeli

🚨 IMPORTANT UPDATE FOR EVERYONE FACING FIREBASE LOGIN ERRORS 🚨

If you are getting any of the following errors while using Firebase CLI, Flutter, Android Studio, PowerShell, or Command Prompt, then this solution may help you:

❌ Authentication Error: Your credentials are no longer valid. Please run firebase login --reauth

❌ Error: Unable to authenticate using the provided code. Please try again.

❌ Firebase CLI Login Failed

❌ Firebase Authentication Error

❌ Firebase Login Not Working

❌ Firebase Login Authorization Failed

❌ Firebase Login Session Expired

❌ Firebase Login Reauthentication Failed

❌ Firebase CLI Unable to Authenticate

❌ Firebase Login Token Expired

❌ Firebase Login Browser Authentication Failed

I personally faced this problem while configuring Firebase for my Flutter project. I spent a lot of time trying different commands, reinstalling Firebase CLI, and repeating the login process, but the issue continued. After testing multiple solutions, I finally found a working fix.

🎥 COMPLETE SOLUTION VIDEO:

👉 https://youtu.be/oP3w_OI435s?si=yBOXlHJWGEk4oO2C

Watch the video carefully and follow every step exactly as shown.

This solution may help if you are facing issues while running:

✔ firebase login

✔ firebase login --reauth

✔ firebase login --debug

✔ firebase logout

✔ firebase init

✔ firebase deploy

✔ firebase projects:list

✔ flutterfire configure

✔ npm install -g firebase-tools

Common searches that may bring you here:

firebase login error

firebase authentication error

firebase cli login failed

firebase login unable to authenticate

firebase login credentials are no longer valid

firebase login reauth not working

firebase login authorization code invalid

firebase login browser issue

firebase login powershell error

firebase login windows 11 error

firebase login windows 10 error

firebase login android studio error

firebase login flutter error

firebase deploy authentication failed

firebase init authentication failed

firebase tools login issue

firebase oauth error

firebase cli authentication failed

firebase login code rejected

firebase login token expired

firebase login session invalid

firebase login after entering authorization code error

firebase login command prompt error

firebase login stuck after browser authentication

firebase login not accepting code

firebase cli latest version login issue

firebase login 2026

firebase login fix 2026

firebase authentication solution

firebase login complete fix

⚠️ Before commenting "Not Working", please mention:

1️⃣ Your Operating System (Windows 10 or Windows 11)

2️⃣ Firebase CLI Version Run: firebase --version

3️⃣ Node.js Version Run: node --version

4️⃣ Exact Error Message

5️⃣ Screenshot of the Error (if possible)

This helps me understand the issue faster and provide a better solution.

📧 For additional assistance:

[[email protected]](mailto:[email protected])

I regularly check comments and emails and try to help developers facing Firebase, Flutter, Android Studio, Firebase CLI, Authentication, Deployment, Firestore, Hosting, and FlutterFire configuration issues.

If this solution helped you, please:

👍 Like the video

💬 Comment "Solved"

📢 Share it with other Flutter developers

🔔 Subscribe for more Firebase and Flutter tutorials

Happy Coding! 🚀

flutter-for-developers avatar Jun 23 '26 06:06 flutter-for-developers

~ ❯ firebase --version
15.2.1 ~ ❯ node --version
v26.3.1

facing same issue

must-logatta avatar Jun 23 '26 09:06 must-logatta

Downgrading to node v20 works for me !

oleksii-harsher-dev avatar Jun 23 '26 12:06 oleksii-harsher-dev