Skip to content

Add Cookie Support For Firebase Studio #8986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
02c52c6
Added test project to fdc
maneesht Apr 11, 2025
37d0f18
Fixed formatting
maneesht Apr 11, 2025
a4d7813
Fix linting
maneesht Apr 11, 2025
170b15a
Excluded example integration from tsconfig
maneesht Apr 11, 2025
ec405ae
Fixed example-integration package.json
maneesht Apr 11, 2025
248f654
Added ssl check for firestore
maneesht Apr 23, 2025
14ef1bc
Added ssl checks for RTDB
maneesht Apr 23, 2025
a8fe7de
Merge remote-tracking branch 'origin/main' into mtewani/add-ssl-check…
maneesht Apr 23, 2025
df4a115
Removed unnecessary files
maneesht Apr 23, 2025
f867d3b
Removed unnecessary data connect changes
maneesht Apr 23, 2025
4f23f33
Create gentle-laws-kneel.md
maneesht Apr 23, 2025
e755d8c
Addressed feedback
maneesht Apr 28, 2025
ceed5ab
Addressed linting issue
maneesht Apr 28, 2025
44e2d8b
Added functions change
maneesht Apr 28, 2025
a1b85e2
Removed linting rules
maneesht Apr 28, 2025
d67b284
Updated useEmulator
maneesht Apr 28, 2025
a8b208b
Updated functions signatures
maneesht Apr 28, 2025
205f9ca
Updated docsite changes
maneesht Apr 28, 2025
4bc9433
Added tests
maneesht Apr 28, 2025
a32ea8b
Updated docsite
maneesht Apr 28, 2025
07f44b6
Fixed formatting
maneesht Apr 28, 2025
d305dec
Only checked if user is on cloudworkstation for ssl
maneesht Apr 29, 2025
fc6469a
Removed ssl from storage compat
maneesht Apr 29, 2025
0a0cb7a
Revert devsite changes
maneesht Apr 29, 2025
25f8be9
Added return type
maneesht Apr 29, 2025
59ab583
Fixed tests
maneesht Apr 29, 2025
d473c45
Removed changeset
maneesht Apr 29, 2025
43b4d6d
Create nice-plants-thank.md
maneesht Apr 29, 2025
5538911
Fixed test
maneesht Apr 29, 2025
54f2d7a
Merge branch 'mtewani/auto-ssl-cloudworkstations' of https://github.c…
maneesht Apr 29, 2025
0b807f9
Fixed firestore test
maneesht Apr 29, 2025
e6f8263
Added public tag to
maneesht Apr 29, 2025
8749b83
Added code to pass on credentials if using a cloud workstation
maneesht Apr 29, 2025
5ae4e9e
Addressed comments
maneesht Apr 24, 2025
9e408ac
Create nine-pugs-crash.md
maneesht Apr 23, 2025
83da6b1
Removed unused import
maneesht Apr 24, 2025
a8df49c
include storage changes
maneesht Apr 24, 2025
903d3b7
Removed unnecessary import
maneesht Apr 25, 2025
7291e56
Fix formatting
maneesht Apr 25, 2025
411b72d
Fixed data connect test
maneesht Apr 25, 2025
3ce5912
Included extra url in externs
maneesht Apr 25, 2025
ff41e76
Fixed fdc tests
maneesht Apr 25, 2025
c014176
Passed in emulator information
maneesht Apr 25, 2025
a57e5e9
Fixed formattign
maneesht Apr 25, 2025
f5930ab
WIP
maneesht Apr 25, 2025
b486cd7
WIP
maneesht Apr 28, 2025
79ea2d0
Got tests to work
maneesht Apr 28, 2025
cdb502c
Fixed up tests
maneesht Apr 28, 2025
c58a289
Fixed formatting
maneesht Apr 28, 2025
80f29d4
Added data connect test for fetches
maneesht Apr 29, 2025
9d76cb3
Cleaned up auth tests
maneesht Apr 29, 2025
2893ee2
Removed only from auth test
maneesht Apr 29, 2025
9d77dbb
More test cleanup
maneesht Apr 29, 2025
2722d47
Merge remote-tracking branch 'origin/main' into mtewani/fix-auth-redi…
maneesht Apr 29, 2025
862fb91
Added test for storage
maneesht Apr 29, 2025
6d63073
Make param required
maneesht Apr 29, 2025
48d56ed
Added test for fetch for firestore
maneesht Apr 29, 2025
7449c01
Fixed linting
maneesht Apr 29, 2025
11a6004
Really fix linting
maneesht Apr 29, 2025
1adc0ae
Added cookie support in firebase studio
maneesht Apr 29, 2025
b439cca
Fixed linting issues
maneesht Apr 29, 2025
226be0b
Included credential forwarding
maneesht Apr 29, 2025
d660fab
Renamed function
maneesht Apr 29, 2025
e471cf7
Merge remote-tracking branch 'origin/main' into mtewani/add-cookie-su…
maneesht Apr 30, 2025
b3427c5
Removed app check changes
maneesht Apr 30, 2025
b95a71c
Removed the test changes
maneesht Apr 30, 2025
58367e1
Fix formatting
maneesht Apr 30, 2025
9edcd82
Fixed formatting
maneesht Apr 30, 2025
9de2506
Added rtdb changes
maneesht Apr 30, 2025
78a4fea
Updated comments
maneesht Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ export function ordinal(i: number): string;
// @public (undocumented)
export type PartialObserver<T> = Partial<Observer<T>>;

// @public
export function pingServer(endpoint: string): Promise<boolean>;

// Warning: (ae-internal-missing-underscore) The name "promiseWithTimeout" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal
Expand Down
7 changes: 6 additions & 1 deletion packages/auth/src/core/auth/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Auth } from '../../model/public_types';
import { AuthErrorCode } from '../errors';
import { _assert } from '../util/assert';
import { _castAuth } from './auth_impl';
import { deepEqual } from '@firebase/util';
import { deepEqual, isCloudWorkstation, pingServer } from '@firebase/util';

/**
* Changes the {@link Auth} instance to communicate with the Firebase Auth Emulator, instead of production
Expand Down Expand Up @@ -100,6 +100,11 @@ export function connectAuthEmulator(
if (!disableWarnings) {
emitEmulatorWarning();
}

// Workaround to get cookies in Firebase Studio
if (isCloudWorkstation(host)) {
void pingServer(`${protocol}//${host}:${port}`);
}
}

function extractProtocol(url: string): string {
Expand Down
5 changes: 5 additions & 0 deletions packages/data-connect/src/api/DataConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { Provider } from '@firebase/component';
import { isCloudWorkstation, pingServer } from '@firebase/util';

import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
import { Code, DataConnectError } from '../core/error';
Expand Down Expand Up @@ -237,6 +238,10 @@ export function connectDataConnectEmulator(
port?: number,
sslEnabled = false
): void {
// Workaround to get cookies in Firebase Studio
if (isCloudWorkstation(host)) {
void pingServer(`https://${host}${port ? `:${port}` : ''}`);
}
dc.enableEmulator({ host, port, sslEnabled });
}

Expand Down
8 changes: 7 additions & 1 deletion packages/database/src/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
deepEqual,
EmulatorMockTokenOptions,
getDefaultEmulatorHostnameAndPort,
isCloudWorkstation
isCloudWorkstation,
pingServer
} from '@firebase/util';

import { AppCheckTokenProvider } from '../core/AppCheckTokenProvider';
Expand Down Expand Up @@ -389,6 +390,11 @@ export function connectDatabaseEmulator(
tokenProvider = new EmulatorTokenProvider(token);
}

// Workaround to get cookies in Firebase Studio
if (isCloudWorkstation(host)) {
void pingServer(host);
}

// Modify the repo to apply emulator settings
repoManagerApplyEmulatorSettings(repo, hostAndPort, options, tokenProvider);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
FirebaseApp,
getApp
} from '@firebase/app';
import { deepEqual, getDefaultEmulatorHostnameAndPort } from '@firebase/util';
import {
deepEqual,
getDefaultEmulatorHostnameAndPort,
isCloudWorkstation,
pingServer
} from '@firebase/util';

import { User } from '../auth/user';
import {
Expand Down Expand Up @@ -194,6 +199,11 @@ export function initializeFirestore(
);
}

// Workaround to get cookies in Firebase Studio
if (settings.host && isCloudWorkstation(settings.host)) {
void pingServer(settings.host);
}

return provider.initialize({
options: settings,
instanceIdentifier: databaseId
Expand Down
6 changes: 5 additions & 1 deletion packages/firestore/src/lite-api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
deepEqual,
EmulatorMockTokenOptions,
getDefaultEmulatorHostnameAndPort,
isCloudWorkstation
isCloudWorkstation,
pingServer
} from '@firebase/util';

import {
Expand Down Expand Up @@ -333,6 +334,9 @@ export function connectFirestoreEmulator(
emulatorOptions: firestore._getEmulatorOptions()
};
const newHostSetting = `${host}:${port}`;
if (useSsl) {
void pingServer(`https://${newHostSetting}`);
}
if (settings.host !== DEFAULT_HOST && settings.host !== newHostSetting) {
logWarn(
'Host has been set in both settings() and connectFirestoreEmulator(), emulator host ' +
Expand Down
6 changes: 5 additions & 1 deletion packages/functions/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { Provider } from '@firebase/component';
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
import { MessagingInternalComponentName } from '@firebase/messaging-interop-types';
import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
import { isCloudWorkstation } from '@firebase/util';
import { isCloudWorkstation, pingServer } from '@firebase/util';

export const DEFAULT_REGION = 'us-central1';

Expand Down Expand Up @@ -179,6 +179,10 @@ export function connectFunctionsEmulator(
functionsInstance.emulatorOrigin = `http${
useSsl ? 's' : ''
}://${host}:${port}`;
// Workaround to get cookies in Firebase Studio
if (useSsl) {
void pingServer(functionsInstance.emulatorOrigin);
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/storage/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import { FirebaseStorage } from './public-types';
import {
createMockUserToken,
EmulatorMockTokenOptions,
isCloudWorkstation
isCloudWorkstation,
pingServer
} from '@firebase/util';
import { Connection, ConnectionType } from './implementation/connection';

Expand Down Expand Up @@ -146,6 +147,10 @@ export function connectStorageEmulator(
): void {
storage.host = `${host}:${port}`;
const useSsl = isCloudWorkstation(host);
// Workaround to get cookies in Firebase Studio
if (useSsl) {
void pingServer(`https://${storage.host}`);
}
storage._isUsingEmulator = true;
storage._protocol = useSsl ? 'https' : 'http';
const { mockUserToken } = options;
Expand Down
12 changes: 12 additions & 0 deletions packages/util/src/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,15 @@
export function isCloudWorkstation(host: string): boolean {
return host.endsWith('.cloudworkstations.dev');
}

/**
* Makes a fetch request to the given server.
* Mostly used for forwarding cookies in Firebase Studio.
* @public
*/
export async function pingServer(endpoint: string): Promise<boolean> {
const result = await fetch(endpoint, {
credentials: 'include'
});
return result.ok;
}
Loading