Skip to content

Redundant token exchange requests when using App Check debug token with concurrent getToken() calls #9184

@nicole0707

Description

@nicole0707

Operating System

macOS Sequoia

Environment (if applicable)

Chrome 138, Node 20.19.2, Next.js 14

Firebase SDK Version

12.0.0

Firebase SDK Product(s)

AppCheck

Project Tooling

Next.js with firebase/app-check

Detailed Problem Description

We’ve observed that when using App Check in debug mode https://github.com/firebase/firebase-js-sdk/blob/main/packages/app-check/src/internal-api.ts#L122-L130, concurrent calls to getToken() (e.g. during page initialization from multiple components) often result in multiple token exchange requests, rather than sharing a single in-flight promise.

In our case, we call getToken() in several places on page load, and even though the first call is still pending, subsequent calls don’t appear to reuse the in-progress request.

We’ve worked around this by implementing our own cached promise wrapper, but ideally, this should be handled inside the SDK, especially in debug mode, where duplicate requests may trigger rate-limiting or test pollution.

Image

Steps and code to reproduce issue

// Assume App Check has already been initialized in debug mode
// and FIREBASE_APPCHECK_DEBUG_TOKEN is set
// Simulate concurrent calls from different parts of the app
Promise.all([
  getToken(appCheck),  // Call 1
  getToken(appCheck),  // Call 2
  getToken(appCheck)   // Call 3
]).then(() => {
  console.log("All token calls completed");
});

In this setup, we expect all three calls to share the same in-flight promise and result in only one network request to the debug token exchange endpoint. However, this triggers three separate exchange requests, which can be seen in the network panel or logs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions