diff --git a/.changeset/lemon-tomatoes-breathe.md b/.changeset/lemon-tomatoes-breathe.md new file mode 100644 index 00000000000..0df04153d61 --- /dev/null +++ b/.changeset/lemon-tomatoes-breathe.md @@ -0,0 +1,5 @@ +--- +"@firebase/auth": patch +--- + +Fix issue where auth port wasn't properly set when setting up cookies in Firebase Studio. diff --git a/packages/auth/src/core/auth/emulator.test.ts b/packages/auth/src/core/auth/emulator.test.ts index 47c5d927c44..5b3ba360c11 100644 --- a/packages/auth/src/core/auth/emulator.test.ts +++ b/packages/auth/src/core/auth/emulator.test.ts @@ -29,6 +29,7 @@ import { Endpoint } from '../../api'; import { UserInternal } from '../../model/user'; import { _castAuth } from './auth_impl'; import { connectAuthEmulator } from './emulator'; +import * as Util from '@firebase/util'; use(sinonChai); use(chaiAsPromised); @@ -38,8 +39,10 @@ describe('core/auth/emulator', () => { let user: UserInternal; let normalEndpoint: fetch.Route; let emulatorEndpoint: fetch.Route; + let utilStub: sinon.SinonStub; beforeEach(async () => { + utilStub = sinon.stub(Util, 'pingServer'); auth = await testAuth(); user = testUser(_castAuth(auth), 'uid', 'email', true); fetch.setUp(); @@ -154,6 +157,19 @@ describe('core/auth/emulator', () => { ); } }); + it('calls pingServer with port if specified', () => { + connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev:2020'); + expect(utilStub).to.have.been.calledWith( + 'https://abc.cloudworkstations.dev:2020' + ); + }); + + it('calls pingServer with no port if none specified', () => { + connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev'); + expect(utilStub).to.have.been.calledWith( + 'https://abc.cloudworkstations.dev' + ); + }); it('logs out a warning to the console', () => { sinon.stub(console, 'info'); diff --git a/packages/auth/src/core/auth/emulator.ts b/packages/auth/src/core/auth/emulator.ts index 05f2e5e4bd5..8547f7bad6c 100644 --- a/packages/auth/src/core/auth/emulator.ts +++ b/packages/auth/src/core/auth/emulator.ts @@ -103,7 +103,7 @@ export function connectAuthEmulator( // Workaround to get cookies in Firebase Studio if (isCloudWorkstation(host)) { - void pingServer(`${protocol}//${host}:${port}`); + void pingServer(`${protocol}//${host}${portStr}`); } }