Skip to content

Commit 9cc1156

Browse files
committed
Re-add emitEmulatorWarning that was not part of the emulator overlay
1 parent fa2e78a commit 9cc1156

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function connectAuthEmulator(
8383
// once Auth has started to make network requests.
8484
_assert(
8585
deepEqual(emulator, authInternal.config.emulator) &&
86-
deepEqual(emulatorConfig, authInternal.emulatorConfig),
86+
deepEqual(emulatorConfig, authInternal.emulatorConfig),
8787
authInternal,
8888
AuthErrorCode.EMULATOR_CONFIG_FAILED
8989
);
@@ -100,6 +100,8 @@ export function connectAuthEmulator(
100100
if (isCloudWorkstation(host)) {
101101
// Workaround to get cookies in Firebase Studio
102102
void pingServer(`${protocol}//${host}${portStr}`);
103+
} else if (!disableWarnings) {
104+
emitEmulatorWarning();
103105
}
104106
}
105107

@@ -138,3 +140,39 @@ function parsePort(portStr: string): number | null {
138140
}
139141
return port;
140142
}
143+
144+
function emitEmulatorWarning(): void {
145+
function attachBanner(): void {
146+
const el = document.createElement('p');
147+
const sty = el.style;
148+
el.innerText =
149+
'Running in emulator mode. Do not use with production credentials.';
150+
sty.position = 'fixed';
151+
sty.width = '100%';
152+
sty.backgroundColor = '#ffffff';
153+
sty.border = '.1em solid #000000';
154+
sty.color = '#b50000';
155+
sty.bottom = '0px';
156+
sty.left = '0px';
157+
sty.margin = '0px';
158+
sty.zIndex = '10000';
159+
sty.textAlign = 'center';
160+
el.classList.add('firebase-emulator-warning');
161+
document.body.appendChild(el);
162+
}
163+
164+
if (typeof console !== 'undefined' && typeof console.info === 'function') {
165+
console.info(
166+
'WARNING: You are using the Auth Emulator,' +
167+
' which is intended for local testing only. Do not use with' +
168+
' production credentials.'
169+
);
170+
}
171+
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
172+
if (document.readyState === 'loading') {
173+
window.addEventListener('DOMContentLoaded', attachBanner);
174+
} else {
175+
attachBanner();
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)