Skip to content

Commit 71ee5cb

Browse files
committed
Added more descriptive state checking for asserts
1 parent d9fa204 commit 71ee5cb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/auth/src/core/auth/emulator.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,27 @@ export function connectAuthEmulator(
6969
options: Object.freeze({ disableWarnings })
7070
});
7171

72+
// There are a few scenarios to guard against if the Auth instance has already started:
7273
if (!authInternal._canInitEmulator) {
74+
// Applications may not initialize the emulator for the first time if Auth has already started
75+
// to make network requests.
7376
_assert(
74-
deepEqual(emulator, authInternal.config.emulator || {}) &&
75-
deepEqual(emulatorConfig, authInternal.emulatorConfig || {}),
77+
authInternal.config.emulator && authInternal.emulatorConfig,
7678
authInternal,
7779
AuthErrorCode.EMULATOR_CONFIG_FAILED
7880
);
81+
82+
// Applications may not alter the configuration of the emulator (aka pass a different config)
83+
// once Auth has started to make network requests.
84+
_assert(
85+
deepEqual(emulator, authInternal.config.emulator) &&
86+
deepEqual(emulatorConfig, authInternal.emulatorConfig),
87+
authInternal,
88+
AuthErrorCode.EMULATOR_CONFIG_FAILED
89+
);
90+
91+
// It's valid, however, to invoke connectAuthEmulator() after Auth has started making
92+
// connections, so long as the config matches the existing config. This results in a no-op.
7993
return;
8094
}
8195

0 commit comments

Comments
 (0)