Skip to content

Commit 79f4a5a

Browse files
authored
Make the emulator API match for auth-exp (#3925)
* Make the signature for emulator API match in auth-exp * Formatting * PR feeback
1 parent 10f038f commit 79f4a5a

File tree

8 files changed

+16
-22
lines changed

8 files changed

+16
-22
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export class Auth implements compat.FirebaseAuth, Wrapper<externs.Auth> {
8282
signOut(): Promise<void> {
8383
return this.auth.signOut();
8484
}
85-
85+
useEmulator(url: string): void {
86+
this.auth.useEmulator(url);
87+
}
8688
applyActionCode(code: string): Promise<void> {
8789
return impl.applyActionCode(this.auth, code);
8890
}

packages-exp/auth-exp/src/api/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ describe('api/_performApiRequest', () => {
358358

359359
it('works properly with an emulated environment', () => {
360360
(auth.config as ConfigInternal).emulator = {
361-
hostname: 'localhost',
362-
port: 5000
361+
url: 'http://localhost:5000'
363362
};
364363
expect(_getFinalTarget(auth, 'host', '/path', 'query=test')).to.eq(
365364
'http://localhost:5000/host/path?query=test'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,14 @@ describe('core/auth/auth_impl useEmulator', () => {
441441
context('useEmulator', () => {
442442
it('fails if a network request has already been made', async () => {
443443
await user.delete();
444-
expect(() => auth.useEmulator('localhost', 2020)).to.throw(
444+
expect(() => auth.useEmulator('http://localhost:2020')).to.throw(
445445
FirebaseError,
446446
'auth/emulator-config-failed'
447447
);
448448
});
449449

450450
it('updates the endpoint appropriately', async () => {
451-
auth.useEmulator('localhost', 2020);
451+
auth.useEmulator('http://localhost:2020');
452452
await user.delete();
453453
expect(normalEndpoint.calls.length).to.eq(0);
454454
expect(emulatorEndpoint.calls.length).to.eq(1);

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,12 @@ export class AuthImpl implements Auth, _FirebaseService {
179179
this.languageCode = _getUserLanguage();
180180
}
181181

182-
useEmulator(hostname: string, port: number): void {
182+
useEmulator(url: string): void {
183183
assert(this._canInitEmulator, AuthErrorCode.EMULATOR_CONFIG_FAILED, {
184184
appName: this.name
185185
});
186186

187-
this.config.emulator = {
188-
hostname,
189-
port
190-
};
191-
187+
this.config.emulator = { url };
192188
this.settings.appVerificationDisabledForTesting = true;
193189
}
194190

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import { _emulatorUrl } from './emulator';
2323
describe('core/util/emulator', () => {
2424
const config: ConfigInternal = {
2525
emulator: {
26-
hostname: 'localhost',
27-
port: 4000
26+
url: 'http://localhost:4000'
2827
}
2928
} as ConfigInternal;
3029

3130
it('builds the proper URL with no path', () => {
32-
expect(_emulatorUrl(config)).to.eq('http://localhost:4000');
31+
expect(_emulatorUrl(config)).to.eq('http://localhost:4000/');
3332
});
3433

3534
it('builds the proper URL with a path', () => {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ import { debugAssert } from './assert';
2020

2121
export function _emulatorUrl(config: ConfigInternal, path?: string): string {
2222
debugAssert(config.emulator, 'Emulator should always be set here');
23-
const { hostname, port } = config.emulator;
23+
const { url } = config.emulator;
24+
const emulatorHost = new URL(url).toString();
2425

25-
const base = `http://${hostname}:${port}`;
2626
if (!path) {
27-
return base;
27+
return emulatorHost;
2828
}
2929

30-
const sep = path.startsWith('/') ? '' : '/';
31-
return `${base}${sep}${path}`;
30+
return `${emulatorHost}${path.startsWith('/') ? path.slice(1) : path}`;
3231
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ export type AuthDomain = string;
2626

2727
export interface ConfigInternal extends externs.Config {
2828
emulator?: {
29-
hostname: string;
30-
port: number;
29+
url: string;
3130
};
3231
}
3332

packages-exp/auth-types-exp/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export interface Auth {
137137
readonly currentUser: User | null;
138138
updateCurrentUser(user: User | null): Promise<void>;
139139
useDeviceLanguage(): void;
140-
useEmulator(hostname: string, port: number): void;
140+
useEmulator(url: string): void;
141141
signOut(): Promise<void>;
142142
}
143143

0 commit comments

Comments
 (0)