169

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@example.com'

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
uber
  • 4,163
  • 5
  • 26
  • 55

23 Answers23

355

For me this worked,

firebase logout

firebase login

Akhilesh Kumar
  • 4,127
  • 1
  • 11
  • 10
62

This worked for me:

Run

firebase use --add

And re-select the project

user14739916
  • 629
  • 4
  • 2
58

Simply

use firebase login --reauth

Abraham
  • 12,140
  • 4
  • 56
  • 92
15

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.

WebDevJ
  • 221
  • 1
  • 3
  • 6
7

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
Monu Rohilla
  • 1,311
  • 5
  • 20
7

Run

firebase use --add

And re-select the project

This works 100%

Sanket Shelke
  • 101
  • 1
  • 2
5

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]
Mark_Fu
  • 51
  • 1
  • 2
4

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

Rami Alloush
  • 2,308
  • 2
  • 27
  • 33
3

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

Neel Dsouza
  • 1,342
  • 4
  • 15
  • 33
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
2

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

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32743150) – Kumar Saurabh Sep 23 '22 at 12:05
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
Rasel Khan
  • 2,976
  • 19
  • 25
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.

牛郑杰
  • 11
  • 1
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.

John Cummings
  • 1,949
  • 3
  • 22
  • 38
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"
Tim Van Laer
  • 2,434
  • 26
  • 30
1

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.

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
  • 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](/help/how-to-answer). – Community Jul 19 '23 at 08:28
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.

Xin
  • 33,823
  • 14
  • 84
  • 85
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

Ronen Rabinovici
  • 8,680
  • 5
  • 34
  • 46
-1

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

KnownColor
  • 449
  • 5
  • 12