183

I tried running firebase deploy like I have always done but came across this Error:

Error: Failed to get Firebase project project-name. Please make sure the project exists and your account has permission to access it.

I have run firebase login and I get 'Already logged in as [email protected]'

The firebase-debug.log file shows a few 401 http responses and some of them have the following text:

'Request had invalid authentication credentials' and also 'invalid token'

How can this be solved?

5
  • do you have a stacktrace of the error? like 401 / 503 etc? Aug 18, 2020 at 17:38
  • 128
    Try reauthenticating using firebase login --reauth. Aug 18, 2020 at 18:19
  • 4
    I would suggest you 1) updating to the latest Firebase CLI version, 2) as Sushan suggested, run firebase login --reauth, then try firebase deploy again and let us know of the output.
    – tzovourn
    Aug 19, 2020 at 9:03
  • 1
    Updating to the firebase CLI version fixed it for me. Dec 28, 2021 at 6:52
  • It looks like this is a recurrent problem with some new firebase-tools versions Jun 21 at 9:13

23 Answers 23

385

For me this worked,

firebase logout

firebase login

6
  • 3
    I was facing a similar issue. It was showing already logged in as well. But when I tried to logout and login then it worked.
    – Aman Khare
    Sep 9, 2020 at 11:39
  • 5
    Worked great. Even though Firebase says you're logged in, when you log out you'll see: "Invalid refresh token for [email protected], did not need to deauthorize"
    – Slbox
    Sep 6, 2021 at 23:54
  • 1
    old joke: close all windows and restart :)
    – Ayyash
    Feb 15, 2022 at 16:28
  • Maybe I am just stupid but I am facing this error at GitHub. Where to put this command?
    – OndrejHj04
    Apr 5, 2022 at 9:07
  • 1
    After I updated npm and was trying to add a function to Cloud Functions I got an error that said I had to update firebase-tools: npm install -g firebase-tools. What seems to has happened is there were new permissions that I had to either accept or decline and using this logouts/login answer showed me the permissions after I logged in. Then everything worked fine. Jun 20, 2022 at 21:46
64

This worked for me:

Run

firebase use --add

And re-select the project

3
  • 2
    Logging in and out & firebase use -add worked for me. Aug 28, 2021 at 15:02
  • 1
    This was needed as it lost context. Had logged in before this, so login / logout was not the solution.
    – Daniel ZA
    Oct 29, 2021 at 14:33
  • This worked for me too.
    – vlntn
    Oct 23 at 14:48
58

Simply

use firebase login --reauth

3
  • 2
    this is the correct solution. i just tested it with similar issue. May 4, 2022 at 15:12
  • 1
    works for me!!! thnx.
    – Sanjay
    Jan 13 at 11:26
  • 1
    This actually worked, what an annoying an unnecessary problem, why is it that Google doesn't allow us to upload code directly through the Firebase web console the way AWS does blows my mind..... Jul 25 at 19:40
16

For me, I was setting up a new machine with an existing firebase project. This is what I did:

First successfully login to firebase from your command console

firebase login

Get a list of your projects

firebase projects:list

Tell firebase which project you are using

firebase use <Project ID>

Then, I was able to deploy and use other commands for this project. Hope this helps someone.

1
  • Thanks. This worked for me after selecting another project first and then re-selecting the project I was working on.
    – Mrvonwyl
    Nov 19 at 11:06
8

sometimes there is a token error you can check debug.log

Error Message in debug.log : [debug] [2020-10-13T23:01:28.050Z] <<< HTTP RESPONSE BODY {"error":{"code":401,"message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}}

Solution of error use

firebase login --reauth

and again firebase init for reinitializing the project select project and

firebase deploy
7

Run

firebase use --add

And re-select the project

This works 100%

6

Try logging out of firebase CLI and then log back in with the account that has the project that you are trying to run.

This was the case with me. I was logged in to another firebase account.

Steps:

  1. `firebase logout`
    
  2. `firebase login`
    
5

1.run this firebase logout firebase login 2.if u can not login successfully , like this ? [https://i.stack.imgur.com/4MJM5.png][1]

  1. run this , export http_proxy=http://localhost:your proxy port 4.successfully!!! [https://i.stack.imgur.com/sRcvG.png][1]
4

Disconnecting the company's VPN and trying it again worked for me.

1
  • 1
    I can't believe VPN was my issue Feb 1, 2021 at 8:18
4

Any typo inside the .firebaserc would show this error. For me I had an extra comma, removing it solved the error.

3

If none of the other answers worked for you, I had the same problem and received this solution from Firebase Support. (ty Sergei)

My system will occasionally create and Environment Variable named FIREBASE_TOKEN. The token will expire, but the variable does not. Restarts and logout/login cycles did nothing. Deleting the variable works every time though.

Remove-Item Env:\FIREBASE_TOKEN
3

If you are hosting multiple projects in multiple accounts then you'll get this error mostly so follow the below commands.

  1. logout first using firebase logout
  2. login then using firebase login

While logging in select the firebase account you want to use for the project.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jul 19 at 8:28
2

It is possible you are trying to deploy without internet connection. The first thing to look for is if your internet is okay.

1
2

Make sure that you don't have this file .firebaserc already existing in your project directory if you already do!

Delete it and try firebase init in console again.

1

It's really awesome and confusing------>

just did these command ->

> firebase logout
> 
> firebase login
1

if you use Mac or Linux, you can write this command export http_proxy=http://127.0.0.1:1087 to make sure your terminal uses the proxy, which is useful for me.

1

None of the above solutions worked for me but removing/editing the stored value of the default project in $HOME/.config/configstore/firebase-tools.json did work.

1

If you have this issue in a CI pipeline, you can regenerate a token on your local machine with

firebase login:ci

Put the generated token as an environment variable, e.g. FIREBASE_TOKEN and run like this:

firebase deploy --token "$FIREBASE_TOKEN"
0

I got this error. when I used these commands in the VS Code terminal.

Solution

  • Try typing 'cmd' in the same Vs Code terminal and give the Firebase commands.

(or)

  • Try in the command prompt terminal.
0

I am also facing that problem and solved the below process First firebase logout then firebase login, after npm run build, firebase deploy. It is now working.

0

I have faced similar issue. I have fixed using this work flow, check which one is missing on your side:

  1. Add and choose the env: firebase use --add e.g. uat

    If you already have the env, please just firebase use uat

  2. After choosing the env from step 1, run firebase init hosting:github Follow some steps, and input the github link, which then will generate the token for you. (rest steps does not matter if you exit or not)

You now have a secrets created in github already, and the firebase can access github to continue build.

0

For me - none of the other answers worked - but this did: npm install -g firebase-tools (which updates the firebase CLI)

And a helpful tip - apparently they have good support - use the following form: https://firebase.google.com/support/troubleshooter/products/other

-1

I got this error in Linux when I was out of disk space, freeing some space resolved it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.