226

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

5 Answers 5

640

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

4
  • 1
    Glad to help :)
    – M.Ali
    Commented Nov 9, 2018 at 18:46
  • 28
    Note: To log out, use firebase logout, then log back in with firebase login Commented Jan 21, 2019 at 9:17
  • 3
    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
    Commented Feb 7, 2020 at 18:12
  • That saved my day <3 Commented Jul 6, 2024 at 18:52
45

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

24

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.

5
  • 1
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Jan 10, 2022 at 4: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
    Commented Jan 10, 2022 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
    Commented Apr 24, 2023 at 9: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
    Commented Apr 25, 2023 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
    Commented May 1, 2023 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

0

In my case, just doing 'firebase login --reauth' didn't work. When I did 'firebase login', it showed that I was logged in but with some deprecation warning: screenshot of my terminal

Turned out the node.js version was the problem. I updated it by following this answer (upgrade node js to the latest version on mac), launched a new terminal, and firebase command worked without 401 error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.