Skip to content

Commit 1adc0ae

Browse files
committed
Added cookie support in firebase studio
1 parent 11a6004 commit 1adc0ae

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

common/api-review/util.api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ export interface Subscribe<T> {
474474
(observer: PartialObserver<T>): Unsubscribe;
475475
}
476476

477+
// Warning: (ae-missing-release-tag) "testConnectionAlive" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
478+
//
479+
// @public (undocumented)
480+
export function testConnectionAlive(endpoint: string): Promise<boolean>;
481+
477482
// Warning: (ae-missing-release-tag) "Unsubscribe" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
478483
//
479484
// @public (undocumented)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import { Auth } from '../../model/public_types';
1818
import { AuthErrorCode } from '../errors';
1919
import { _assert } from '../util/assert';
2020
import { _castAuth } from './auth_impl';
21-
import { deepEqual } from '@firebase/util';
21+
import {
22+
deepEqual,
23+
isCloudWorkstation,
24+
testConnectionAlive
25+
} from '@firebase/util';
2226

2327
/**
2428
* Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
@@ -100,6 +104,11 @@ export function connectAuthEmulator(
100104
if (!disableWarnings) {
101105
emitEmulatorWarning();
102106
}
107+
108+
if (isCloudWorkstation(host)) {
109+
// Workaround to get cookies in Firebase Studio
110+
testConnectionAlive(`${protocol}//${host}:${port}`).then().catch();
111+
}
103112
}
104113

105114
function extractProtocol(url: string): string {

packages/data-connect/src/api/DataConnect.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
import { RESTTransport } from '../network/transport/rest';
4343

4444
import { MutationManager } from './Mutation';
45+
import { isCloudWorkstation, testConnectionAlive } from '@firebase/util';
4546

4647
/**
4748
* Connector Config for calling Data Connect backend.
@@ -237,6 +238,9 @@ export function connectDataConnectEmulator(
237238
port?: number,
238239
sslEnabled = false
239240
): void {
241+
if (isCloudWorkstation(host)) {
242+
testConnectionAlive(`https://${host}${port ? `:${port}` : ''}`);
243+
}
240244
dc.enableEmulator({ host, port, sslEnabled });
241245
}
242246

packages/firestore/src/lite-api/database.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
deepEqual,
2828
EmulatorMockTokenOptions,
2929
getDefaultEmulatorHostnameAndPort,
30-
isCloudWorkstation
30+
isCloudWorkstation,
31+
testConnectionAlive
3132
} from '@firebase/util';
3233

3334
import {
@@ -333,6 +334,9 @@ export function connectFirestoreEmulator(
333334
emulatorOptions: firestore._getEmulatorOptions()
334335
};
335336
const newHostSetting = `${host}:${port}`;
337+
if (useSsl) {
338+
testConnectionAlive(`https://${newHostSetting}`);
339+
}
336340
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
337341
logWarn(
338342
'Host has been set in both settings() and connectFirestoreEmulator(), emulator host ' +

packages/functions/src/service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { Provider } from '@firebase/component';
3030
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
3131
import { MessagingInternalComponentName } from '@firebase/messaging-interop-types';
3232
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
33-
import { isCloudWorkstation } from '@firebase/util';
33+
import { isCloudWorkstation, testConnectionAlive } from '@firebase/util';
3434

3535
export const DEFAULT_REGION = 'us-central1';
3636

@@ -179,6 +179,9 @@ export function connectFunctionsEmulator(
179179
functionsInstance.emulatorOrigin = `http${
180180
useSsl ? 's' : ''
181181
}://${host}:${port}`;
182+
if (useSsl) {
183+
testConnectionAlive(functionsInstance.emulatorOrigin);
184+
}
182185
}
183186

184187
/**

packages/storage/src/service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import { FirebaseStorage } from './public-types';
4545
import {
4646
createMockUserToken,
4747
EmulatorMockTokenOptions,
48-
isCloudWorkstation
48+
isCloudWorkstation,
49+
testConnectionAlive
4950
} from '@firebase/util';
5051
import { Connection, ConnectionType } from './implementation/connection';
5152

@@ -146,6 +147,9 @@ export function connectStorageEmulator(
146147
): void {
147148
storage.host = `${host}:${port}`;
148149
const useSsl = isCloudWorkstation(host);
150+
if (useSsl) {
151+
testConnectionAlive(`https://${storage.host}`);
152+
}
149153
storage._isUsingEmulator = true;
150154
storage._protocol = useSsl ? 'https' : 'http';
151155
const { mockUserToken } = options;

packages/util/src/url.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222
export function isCloudWorkstation(host: string): boolean {
2323
return host.endsWith('.cloudworkstations.dev');
2424
}
25+
26+
export async function testConnectionAlive(endpoint: string): Promise<boolean> {
27+
const result = await fetch(endpoint);
28+
return result.ok;
29+
}

0 commit comments

Comments
 (0)