Messaging getToken() rejects with "Installations: Generate Auth Token request failed with error 404 NOT_FOUND" after the FID was deleted server-side, instead of re-registering

Open
#10,580 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
firebase, typescript

Research direction

Start with packages/installations/src/helpers/refresh-auth-token.ts and packages/messaging/src/internals/requests.ts, then trace the tests for auth token refresh and Messaging getToken(). Check how a 401 or 404 response removes the local installation and how Messaging handles the resulting rejection. Done means the first getToken() call re-registers and retries once after a 404, with tests covering that flow.

Written by the indexing model from the issue text.

Description

api: installations api: messaging reproducible type: feature request
Operating System

Not OS-specific (web SDK code path). Seen in production on Android Chrome (reduced UA reports "Android 10", real version unknown); reproduced on Windows 11 with Chrome.

Environment (if applicable)

Chrome 155 on Android (mobile web, production). Also reproduced on desktop Chrome, Windows 11.

Firebase SDK Version

12.19.0 (@firebase/installations 0.6.24, @firebase/messaging 0.13.3)

Firebase SDK Product(s)

Installations, Messaging

Project Tooling

Angular 22 application built with the Angular CLI application builder (esbuild), TypeScript 6

Detailed Problem Description

The Installations docs state that the backend deletes a Firebase installation ID (FID) after 270 days of inactivity
(https://firebase.google.com/docs/projects/manage-installations). The web SDK keeps the old FID and its auth token in
IndexedDB. When such a user comes back, the first authTokens:generate call returns 404 NOT_FOUND and
getToken(messaging) rejects with:

FirebaseError: Installations: Generate Auth Token request failed with error
"404 NOT_FOUND: Requested entity was not found." (installations/request-failed).

The SDK already knows how to heal: fetchAuthTokenFromServer removes the local entry on 401/404 so the next call
registers a new FID, and the next getToken() indeed succeeds. But the first call still rejects, so every app has to
catch this specific error and retry itself. Nothing is actually wrong at that point, and the error message gives no
hint that it is recoverable.

Where it happens:

  • packages/installations/src/helpers/refresh-auth-token.ts, fetchAuthTokenFromServer: on serverCode 401 or 404
    it calls remove(installations.appConfig) and then throw e.
  • packages/messaging/src/internals/requests.ts, getHeaders: await installations.getToken() with no catch.
    requestGetToken awaits getHeaders before its try, so the rejection bypasses the TOKEN_SUBSCRIBE_FAILED
    wrapping and there is no retry (fetchWithExponentialRetry only wraps the fetch in requestCreateRegistration).

installations.getId() swallows the same refresh failure (.catch(console.error)), so only the Messaging path
surfaces it to users.

Expected: after a 404 on authTokens:generate, refreshAuthToken (or Messaging's getToken path) re-registers
the installation and retries once, so getToken(messaging) resolves with a token the same way the second call does.

Related earlier reports, closed as stale without a diagnosis: #8007, #7998 (same 404), #7566 (403 variant).

Steps and code to reproduce issue

Any app that calls getToken(messaging) with notification permission granted. To simulate the server-side deletion
without waiting 270 days:

  1. Load the app once so IndexedDB firebase-installations-database / firebase-installations-store holds a
    registered entry.

  2. In the DevTools console, make the stored FID unknown to the server and force a token refresh, then reload:

    const req = indexedDB.open('firebase-installations-database');
    req.onsuccess = () => {
      const tx = req.result.transaction('firebase-installations-store', 'readwrite');
      const store = tx.objectStore('firebase-installations-store');
      store.openCursor().onsuccess = e => {
        const cursor = e.target.result;
        if (!cursor) return;
        const entry = cursor.value;
        entry.fid = entry.fid.slice(0, -1) + (entry.fid.endsWith('a') ? 'b' : 'a'); // FID the server does not know
        entry.authToken.creationTime = 0;                                              // force a refresh
        cursor.update(entry);
        cursor.continue();
      };
      tx.oncomplete = () => location.reload();
    };
    
  3. Observe: POST .../installations/<fid>/authTokens:generate returns 404 and getToken(messaging) rejects with
    installations/request-failed. The IndexedDB entry is gone.

  4. Reload again: a new FID is registered and getToken(messaging) resolves.

import { getMessaging, getToken } from 'firebase/messaging';

const messaging = getMessaging(app);
await getToken(messaging, { vapidKey }); // first call after the FID was deleted server-side: rejects
await getToken(messaging, { vapidKey }); // second call: resolves
Dominant language
TypeScript
Stars
5.2k
Forks
1k
Avg merge
2d 2h
Merged PRs (30d)
77

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebase-js-sdk

All issues in firebase/firebase-js-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.