Skip to content

Commit 871ef0b

Browse files
committed
Refactor impl into emulator.ts.
1 parent a5817cb commit 871ef0b

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,6 @@ export class AuthImpl implements Auth, _FirebaseService {
272272
this.languageCode = _getUserLanguage();
273273
}
274274

275-
_useEmulator(url: string, options?: { disableWarnings: boolean }): void {
276-
_assert(this._canInitEmulator, this, AuthErrorCode.EMULATOR_CONFIG_FAILED);
277-
278-
_assert(
279-
/^https?:\/\//.test(url),
280-
this,
281-
AuthErrorCode.INVALID_EMULATOR_SCHEME
282-
);
283-
284-
this.config.emulator = { url };
285-
this.settings.appVerificationDisabledForTesting = true;
286-
emitEmulatorWarning(!!options?.disableWarnings);
287-
}
288-
289275
async _delete(): Promise<void> {
290276
this._deleted = true;
291277
}
@@ -570,43 +556,3 @@ class Subscription<T> {
570556
return this.observer.next.bind(this.observer);
571557
}
572558
}
573-
574-
function emitEmulatorWarning(disableBanner: boolean): void {
575-
function attachBanner(): void {
576-
const el = document.createElement('p');
577-
const sty = el.style;
578-
el.innerText =
579-
'Running in emulator mode. Do not use with production credentials.';
580-
sty.position = 'fixed';
581-
sty.width = '100%';
582-
sty.backgroundColor = '#ffffff';
583-
sty.border = '.1em solid #000000';
584-
sty.color = '#ff0000';
585-
sty.bottom = '0px';
586-
sty.left = '0px';
587-
sty.margin = '0px';
588-
sty.zIndex = '10000';
589-
sty.textAlign = 'center';
590-
el.classList.add('firebase-emulator-warning');
591-
document.body.appendChild(el);
592-
}
593-
594-
if (typeof console !== 'undefined' && typeof console.info === 'function') {
595-
console.info(
596-
'WARNING: You are using the Auth Emulator,' +
597-
' which is intended for local testing only. Do not use with' +
598-
' production credentials.'
599-
);
600-
}
601-
if (
602-
typeof window !== 'undefined' &&
603-
typeof document !== 'undefined' &&
604-
!disableBanner
605-
) {
606-
if (document.readyState === 'loading') {
607-
window.addEventListener('DOMContentLoaded', attachBanner);
608-
} else {
609-
attachBanner();
610-
}
611-
}
612-
}

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717
import * as externs from '@firebase/auth-types-exp';
18+
import { AuthErrorCode } from '../errors';
19+
import { _assert } from '../util/assert';
1820
import { _castAuth } from './auth_impl';
1921

2022
/**
@@ -43,5 +45,60 @@ export function useAuthEmulator(
4345
url: string,
4446
options?: { disableWarnings: boolean }
4547
): void {
46-
_castAuth(auth)._useEmulator(url, options);
48+
const authInternal = _castAuth(auth);
49+
_assert(
50+
authInternal._canInitEmulator,
51+
authInternal,
52+
AuthErrorCode.EMULATOR_CONFIG_FAILED
53+
);
54+
55+
_assert(
56+
/^https?:\/\//.test(url),
57+
authInternal,
58+
AuthErrorCode.INVALID_EMULATOR_SCHEME
59+
);
60+
61+
authInternal.config.emulator = { url };
62+
authInternal.settings.appVerificationDisabledForTesting = true;
63+
emitEmulatorWarning(!!options?.disableWarnings);
64+
}
65+
66+
function emitEmulatorWarning(disableBanner: boolean): void {
67+
function attachBanner(): void {
68+
const el = document.createElement('p');
69+
const sty = el.style;
70+
el.innerText =
71+
'Running in emulator mode. Do not use with production credentials.';
72+
sty.position = 'fixed';
73+
sty.width = '100%';
74+
sty.backgroundColor = '#ffffff';
75+
sty.border = '.1em solid #000000';
76+
sty.color = '#ff0000';
77+
sty.bottom = '0px';
78+
sty.left = '0px';
79+
sty.margin = '0px';
80+
sty.zIndex = '10000';
81+
sty.textAlign = 'center';
82+
el.classList.add('firebase-emulator-warning');
83+
document.body.appendChild(el);
84+
}
85+
86+
if (typeof console !== 'undefined' && typeof console.info === 'function') {
87+
console.info(
88+
'WARNING: You are using the Auth Emulator,' +
89+
' which is intended for local testing only. Do not use with' +
90+
' production credentials.'
91+
);
92+
}
93+
if (
94+
typeof window !== 'undefined' &&
95+
typeof document !== 'undefined' &&
96+
!disableBanner
97+
) {
98+
if (document.readyState === 'loading') {
99+
window.addEventListener('DOMContentLoaded', attachBanner);
100+
} else {
101+
attachBanner();
102+
}
103+
}
47104
}

packages-exp/auth-exp/src/model/auth.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export interface Auth extends externs.Auth {
5656
_startProactiveRefresh(): void;
5757
_stopProactiveRefresh(): void;
5858
_getPersistence(): string;
59-
_useEmulator(url: string, options?: { disableWarnings: boolean }): void;
6059

6160
readonly name: AppName;
6261
readonly config: ConfigInternal;

0 commit comments

Comments
 (0)