Skip to content

Commit 1884f14

Browse files
authored
Apply rules to the correct emulated RTDB instance (#3146)
1 parent 46bb52b commit 1884f14

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Fixes issue where OOB flow is not initiated after updating a user's email (#3096)
2+
- Fixes issue where rules are not applied to the default emulated Realtime Database instance (#3124)

src/database/rulesConfig.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export function getRulesConfig(projectId: string, options: any): RulesInstanceCo
4141

4242
if (!Array.isArray(dbConfig)) {
4343
if (dbConfig && dbConfig.rules) {
44-
return [{ rules: dbConfig.rules, instance: options.instance || options.project }];
44+
const instance = options.instance || `${options.project}-default-rtdb`;
45+
return [{ rules: dbConfig.rules, instance }];
4546
} else {
4647
logger.debug("Possibly invalid database config: ", JSON.stringify(dbConfig));
4748
return [];

src/emulator/controller.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { promptOnce } from "../prompt";
3939
import * as rimraf from "rimraf";
4040
import { FLAG_EXPORT_ON_EXIT_NAME } from "./commandUtils";
4141
import { fileExistsSync } from "../fsutils";
42+
import { getDefaultDatabaseInstance } from "../getDefaultDatabaseInstance";
4243

4344
async function getAndCheckAddress(emulator: Emulators, options: any): Promise<Address> {
4445
let host = Constants.normalizeHost(
@@ -494,6 +495,19 @@ export async function startAll(options: any, showUI: boolean = true): Promise<vo
494495
auto_download: true,
495496
};
496497

498+
// Try to fetch the default RTDB instance for a project, but don't hard-fail if we
499+
// can't because the user may be using a fake project.
500+
try {
501+
if (!options.instance) {
502+
options.instance = await getDefaultDatabaseInstance(options);
503+
}
504+
} catch (e) {
505+
databaseLogger.log(
506+
"DEBUG",
507+
`Failed to retrieve default database instance: ${JSON.stringify(e)}`
508+
);
509+
}
510+
497511
const rc = dbRulesConfig.normalizeRulesConfig(
498512
dbRulesConfig.getRulesConfig(projectId, options),
499513
options

0 commit comments

Comments
 (0)