190

I`m trying to set up firebase functions, but I get an error after running firebase init.

Error: HTTP Error: 401, 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.

enter image description here

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
M.Ali
  • 8,815
  • 5
  • 24
  • 42

4 Answers4

540

I solved the problem! you need to logout firebase logout then log-in firebase login again or just refresh the token with firebase login --reauth

it seems that the expiry time of Firebase auth token is limited to max 1Hr

Reza
  • 73
  • 9
M.Ali
  • 8,815
  • 5
  • 24
  • 42
  • 1
    Glad to help :) – M.Ali Nov 09 '18 at 18:46
  • 27
    Note: To log out, use `firebase logout`, then log back in with `firebase login` – Blundering Philosopher Jan 21 '19 at 09:17
  • 1
    I did `firebase login` several times... it said I was already logged in, but it was all a "lie." Disappointed users have to logout & back in or request the reauth explicitly. Why can't they just fail the current login behavior and auto-reauth if nec.? It requires extra work and is a poorer UX. – wescpy Feb 07 '20 at 18:12
41

Use firebase login --reauth, that happened to me because an old FIREBASE_TOKEN was present while trying to exec firebase init

pixshatterer
  • 979
  • 6
  • 12
15

First, manually delete FIREBASE_TOKEN from the Environment Variables on your Windows system, only THEN run firebase login --reauth.

Note: I tried to re-authenticate without deleting the Firebase token first, but it didn't work.

TheFabbius
  • 337
  • 4
  • 12
  • 1
    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/30731241) – glycoaddict Jan 10 '22 at 04:08
  • 1
    I'd have rather commented @pixshatterer's post, but didn't have sufficient points. However, the focus of my answer is on the removal/deletion of the Firebase token, which was not clearly specified by other answers. Moreover, the accepted answer didn't work in my case. It looks like there is a variety of use cases, for which a different solution is required. Maybe we need a summing-up answer. – TheFabbius Jan 10 '22 at 20:36
  • 1
    @TheFabbius How can I delete the FIREBASE_TOKEN? none of the solutions here work for me, but I can not find the environment variable that you mention. – Gerros Apr 24 '23 at 09:31
  • Hey @Gerros, you need to look into your Environment Variables on your Windows system and look for that key. Not sure what OS version you are on, but if you google it you'll easily find a way to access your Env Vars. – TheFabbius Apr 25 '23 at 13:22
  • @TheFabbius thx, I looked it up already but can not find it. I have Win10 and there is no env var FIREBASE_TOKEN – Gerros May 01 '23 at 15:40
0

Had the same issue but with firebase hosting. For some reason only using sudo firebase I managed to make it work