Skip to content

Commit

Permalink
Apply rules to the correct emulated RTDB instance (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Feb 18, 2021
1 parent 46bb52b commit 1884f14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixes issue where OOB flow is not initiated after updating a user's email (#3096)
- Fixes issue where rules are not applied to the default emulated Realtime Database instance (#3124)
3 changes: 2 additions & 1 deletion src/database/rulesConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export function getRulesConfig(projectId: string, options: any): RulesInstanceCo

if (!Array.isArray(dbConfig)) {
if (dbConfig && dbConfig.rules) {
return [{ rules: dbConfig.rules, instance: options.instance || options.project }];
const instance = options.instance || `${options.project}-default-rtdb`;
return [{ rules: dbConfig.rules, instance }];
} else {
logger.debug("Possibly invalid database config: ", JSON.stringify(dbConfig));
return [];
Expand Down
14 changes: 14 additions & 0 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { promptOnce } from "../prompt";
import * as rimraf from "rimraf";
import { FLAG_EXPORT_ON_EXIT_NAME } from "./commandUtils";
import { fileExistsSync } from "../fsutils";
import { getDefaultDatabaseInstance } from "../getDefaultDatabaseInstance";

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

// Try to fetch the default RTDB instance for a project, but don't hard-fail if we
// can't because the user may be using a fake project.
try {
if (!options.instance) {
options.instance = await getDefaultDatabaseInstance(options);
}
} catch (e) {
databaseLogger.log(
"DEBUG",
`Failed to retrieve default database instance: ${JSON.stringify(e)}`
);
}

const rc = dbRulesConfig.normalizeRulesConfig(
dbRulesConfig.getRulesConfig(projectId, options),
options
Expand Down

0 comments on commit 1884f14

Please sign in to comment.