Skip to content

Commit 1b0e7af

Browse files
authored
[Auth] Disable the console.info in connectAuthEmulator() when disableWarnings is passed in (#5564)
* Disable the console.info when disableWarnings is set * Add changeset
1 parent f7d8324 commit 1b0e7af

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

.changeset/gentle-bugs-drop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Calls to `connectAuthEmulator` with the `disableWarnings` flag set to true will no longer cause a `console.info` warning to be printed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,12 @@ describe('core/auth/emulator', () => {
130130
);
131131
});
132132

133-
it('logs out the warning but has no banner if disableBanner true', () => {
133+
it('skips console info and has no banner if warnings disabled', () => {
134134
sinon.stub(console, 'info');
135135
connectAuthEmulator(auth, 'http://localhost:2020', {
136136
disableWarnings: true
137137
});
138-
expect(console.info).to.have.been.calledWith(
139-
'WARNING: You are using the Auth Emulator,' +
140-
' which is intended for local testing only. Do not use with' +
141-
' production credentials.'
142-
);
138+
expect(console.info).not.to.have.been.called;
143139
if (typeof document !== 'undefined') {
144140
expect(document.querySelector('.firebase-emulator-warning')).to.be.null;
145141
}

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export function connectAuthEmulator(
7575
options: Object.freeze({ disableWarnings })
7676
});
7777

78-
emitEmulatorWarning(disableWarnings);
78+
if (!disableWarnings) {
79+
emitEmulatorWarning();
80+
}
7981
}
8082

8183
function extractProtocol(url: string): string {
@@ -114,7 +116,7 @@ function parsePort(portStr: string): number | null {
114116
return port;
115117
}
116118

117-
function emitEmulatorWarning(disableBanner: boolean): void {
119+
function emitEmulatorWarning(): void {
118120
function attachBanner(): void {
119121
const el = document.createElement('p');
120122
const sty = el.style;
@@ -143,8 +145,7 @@ function emitEmulatorWarning(disableBanner: boolean): void {
143145
}
144146
if (
145147
typeof window !== 'undefined' &&
146-
typeof document !== 'undefined' &&
147-
!disableBanner
148+
typeof document !== 'undefined'
148149
) {
149150
if (document.readyState === 'loading') {
150151
window.addEventListener('DOMContentLoaded', attachBanner);

0 commit comments

Comments
 (0)