firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.75k stars 872 forks source link

`User.getIdToken(true)` fails with quota exceeded #8159

Closed ahill187 closed 1 month ago

ahill187 commented 1 month ago

Operating System

Ubuntu 22.04

Browser Version

Chrome/Version 122.0.6261.111 (Official Build) (64-bit)

Firebase SDK Version

10.8.1

Firebase SDK Product:

Auth

Describe your project's tooling

React app with Webpack

Describe the problem

When I make 120 calls to User.getIdToken(true), some of the requests fail with the following error:

{
  "error": {
    "code": 400,
    "message": "QUOTA_EXCEEDED",
    "status": "INVALID_ARGUMENT"
  }
}

I have been unable to find any documentation on the QUOTA_EXCEEDED error code, except in reference to SMS messages. However, my app does not use SMS for authentication. If there is a quota for number of calls to getIdToken(true), this should be documented here: Firebase Javascript Modular Docs: auth.User.getIdToken.

Steps and code to reproduce issue

firebase.utils.js:

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: xxx,
  authDomain: xxx,
  projectId: xxx,
  storageBucket: xxx,
  messagingSenderId: xxx,
  appId: xxx,
  measurementId: xxx
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const auth = getAuth();

Api.tsx:

import axios, { ResponseType } from "axios";
import { auth } from "./firebase/firebase.utils";

const REACT_APP_API_URL = process.env.REACT_APP_API_URL;

export class AuthenticationError extends Error {
  constructor(message: string) {
    super(message);
    this.name = "AuthenticationError";
  }
}

export async function apiPost(
  urlSuffix: string,
  formData: FormData,
  responseType: ResponseType = "json"
): Promise<any> {

  if (auth.currentUser === null) {
    throw new AuthenticationError("User is not logged in, cannot make request to backend.");
  } else {
    const token = await auth.currentUser.getIdToken(true);
    try {
      const url = REACT_APP_API_URL + urlSuffix
      const response = await axios({
        url: url,
        method: "POST",
        data: formData,
        responseType: responseType,
        headers: {
          "Content-Type": "multipart/form-data",
          "Authorization": `Bearer ${token}`,
          "Access-Control-Allow-Headers": "*",
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Methods": "*"
        }
      });
      return response.data;
    } catch (error) {
      throw Error('API request failed: ' + error);
    }
  }
};

When I make a call to apiPost() from another function, the line const token = await auth.currentUser.getIdToken(true); fails if apiPost is called too many times.

DellaBitta commented 1 month ago

Hi @ahill187,

Thanks for the report. That response is generated from the Firebase service. Could you please open a Firebase support ticket? They would be in a better place to help you since they can look into the behavior of the backend to see why this might be happening on your account.

Thanks!.