validateFirebaseProjectId static method

void validateFirebaseProjectId(
  1. String source,
  2. String projectId, {
  3. String path = cloudflareEdgeEntryPath,
})

Rejects a Worker entrypoint pinned to a different Firebase project.

Runtime expressions such as resolveFirebaseProjectId(env) remain valid.

Implementation

static void validateFirebaseProjectId(
  String source,
  String projectId, {
  String path = cloudflareEdgeEntryPath,
}) {
  for (final functionName in [
    "m.FirebaseAuthAdapter",
    "auth.Functions.deleteUser",
  ]) {
    final pattern = RegExp(
      "${RegExp.escape(functionName)}\\s*\\(\\s*\\{\\s*projectId\\s*:\\s*['\"]([^'\"]+)['\"]",
    );
    for (final match in pattern.allMatches(source)) {
      if (match.group(1) != projectId) {
        throw StateError(
          "$path pins $functionName to a different Firebase project. "
          "Use a runtime environment-based project ID before applying or deploying this flavor.",
        );
      }
    }
  }
}