Skip to content

Commit f7ec278

Browse files
Merge main into release
2 parents 136bb73 + 3789b5a commit f7ec278

13 files changed

+138
-29
lines changed

.changeset/afraid-baboons-develop.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@firebase/app-check': minor
3+
'@firebase/app': minor
4+
'@firebase/app-compat': minor
5+
'firebase': minor
6+
---
7+
8+
Default automaticDataCollectionEnabled to true without changing App Check's default behavior.

.changeset/lemon-tomatoes-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix issue where auth port wasn't properly set when setting up cookies in Firebase Studio.

docs-devsite/app.firebaseappsettings.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export interface FirebaseAppSettings
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [automaticDataCollectionEnabled](./app.firebaseappsettings.md#firebaseappsettingsautomaticdatacollectionenabled) | boolean | The settable config flag for GDPR opt-in/opt-out |
25+
| [automaticDataCollectionEnabled](./app.firebaseappsettings.md#firebaseappsettingsautomaticdatacollectionenabled) | boolean | The settable config flag for GDPR opt-in/opt-out. Defaults to true. |
2626
| [name](./app.firebaseappsettings.md#firebaseappsettingsname) | string | custom name for the Firebase App. The default value is <code>&quot;[DEFAULT]&quot;</code>. |
2727

2828
## FirebaseAppSettings.automaticDataCollectionEnabled
2929

30-
The settable config flag for GDPR opt-in/opt-out
30+
The settable config flag for GDPR opt-in/opt-out. Defaults to true.
3131

3232
<b>Signature:</b>
3333

packages/app-check/src/api.test.ts

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,85 @@ describe('api', () => {
239239
expect(getStateReference(app).activated).to.equal(true);
240240
});
241241

242-
it('isTokenAutoRefreshEnabled value defaults to global setting', () => {
242+
it('global false + local unset = false', () => {
243243
app.automaticDataCollectionEnabled = false;
244244
initializeAppCheck(app, {
245245
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY)
246246
});
247247
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
248248
});
249249

250-
it('sets isTokenAutoRefreshEnabled correctly, overriding global setting', () => {
250+
it('global false + local true = false', () => {
251251
app.automaticDataCollectionEnabled = false;
252+
initializeAppCheck(app, {
253+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
254+
isTokenAutoRefreshEnabled: true
255+
});
256+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
257+
});
258+
259+
it('global false + local false = false', () => {
260+
app.automaticDataCollectionEnabled = false;
261+
initializeAppCheck(app, {
262+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
263+
isTokenAutoRefreshEnabled: false
264+
});
265+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
266+
});
267+
268+
it('global unset + local unset = false', () => {
269+
// Global unset should default to true.
270+
initializeAppCheck(app, {
271+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY)
272+
});
273+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
274+
});
275+
276+
it('global unset + local false = false', () => {
277+
// Global unset should default to true.
278+
initializeAppCheck(app, {
279+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
280+
isTokenAutoRefreshEnabled: false
281+
});
282+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
283+
});
284+
285+
it('global unset + local true = true', () => {
286+
// Global unset should default to true.
287+
initializeAppCheck(app, {
288+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
289+
isTokenAutoRefreshEnabled: true
290+
});
291+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(true);
292+
});
293+
294+
it('global true + local unset = false', () => {
295+
app.automaticDataCollectionEnabled = true;
296+
initializeAppCheck(app, {
297+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY)
298+
});
299+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
300+
});
301+
302+
it('global true + local false = false', () => {
303+
app.automaticDataCollectionEnabled = true;
304+
initializeAppCheck(app, {
305+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
306+
isTokenAutoRefreshEnabled: false
307+
});
308+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(false);
309+
});
310+
311+
it('global true + local true = true', () => {
312+
app.automaticDataCollectionEnabled = true;
313+
initializeAppCheck(app, {
314+
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
315+
isTokenAutoRefreshEnabled: true
316+
});
317+
expect(getStateReference(app).isTokenAutoRefreshEnabled).to.equal(true);
318+
});
319+
320+
it('sets isTokenAutoRefreshEnabled correctly, overriding global setting', () => {
252321
initializeAppCheck(app, {
253322
provider: new ReCaptchaV3Provider(FAKE_SITE_KEY),
254323
isTokenAutoRefreshEnabled: true

packages/app-check/src/api.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
} from './internal-api';
4444
import { readTokenFromStorage } from './storage';
4545
import { getDebugToken, initializeDebugMode, isDebugMode } from './debug';
46+
import { logger } from './logger';
4647

4748
declare module '@firebase/component' {
4849
interface NameServiceMapping {
@@ -132,7 +133,7 @@ export function initializeAppCheck(
132133
function _activate(
133134
app: FirebaseApp,
134135
provider: AppCheckProvider,
135-
isTokenAutoRefreshEnabled?: boolean
136+
isTokenAutoRefreshEnabled: boolean = false
136137
): void {
137138
// Create an entry in the APP_CHECK_STATES map. Further changes should
138139
// directly mutate this object.
@@ -149,13 +150,18 @@ function _activate(
149150
return cachedToken;
150151
});
151152

152-
// Use value of global `automaticDataCollectionEnabled` (which
153-
// itself defaults to false if not specified in config) if
154-
// `isTokenAutoRefreshEnabled` param was not provided by user.
153+
// Global `automaticDataCollectionEnabled` (defaults to true) and
154+
// `isTokenAutoRefreshEnabled` must both be true.
155155
state.isTokenAutoRefreshEnabled =
156-
isTokenAutoRefreshEnabled === undefined
157-
? app.automaticDataCollectionEnabled
158-
: isTokenAutoRefreshEnabled;
156+
isTokenAutoRefreshEnabled && app.automaticDataCollectionEnabled;
157+
158+
if (!app.automaticDataCollectionEnabled && isTokenAutoRefreshEnabled) {
159+
logger.warn(
160+
'`isTokenAutoRefreshEnabled` is true but ' +
161+
'`automaticDataCollectionEnabled` was set to false during' +
162+
' `initializeApp()`. This blocks automatic token refresh.'
163+
);
164+
}
159165

160166
state.provider.initialize(app);
161167
}

packages/app-compat/test/firebaseAppCompat.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,17 @@ function firebaseAppTests(
403403
).throws(/'abc'.*exists/i);
404404
});
405405

406-
it('automaticDataCollectionEnabled is `false` by default', () => {
406+
it('automaticDataCollectionEnabled is `true` by default', () => {
407407
const app = firebase.initializeApp({}, 'my-app');
408-
expect(app.automaticDataCollectionEnabled).to.eq(false);
408+
expect(app.automaticDataCollectionEnabled).to.eq(true);
409409
});
410410

411411
it('automaticDataCollectionEnabled can be set via the config object', () => {
412412
const app = firebase.initializeApp(
413413
{},
414-
{ automaticDataCollectionEnabled: true }
414+
{ automaticDataCollectionEnabled: false }
415415
);
416-
expect(app.automaticDataCollectionEnabled).to.eq(true);
416+
expect(app.automaticDataCollectionEnabled).to.eq(false);
417417
});
418418

419419
it('Modifying options object does not change options.', () => {

packages/app/src/api.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ describe('API tests', () => {
128128
{
129129
apiKey: 'test1'
130130
},
131-
{ automaticDataCollectionEnabled: true }
131+
{ automaticDataCollectionEnabled: false }
132132
);
133133
expect(() =>
134134
initializeApp(
135135
{
136136
apiKey: 'test1'
137137
},
138-
{ automaticDataCollectionEnabled: false }
138+
{ automaticDataCollectionEnabled: true }
139139
)
140140
).throws(/\[DEFAULT\].*exists/i);
141141
});
@@ -146,14 +146,14 @@ describe('API tests', () => {
146146
{
147147
apiKey: 'test1'
148148
},
149-
{ name: appName, automaticDataCollectionEnabled: true }
149+
{ name: appName, automaticDataCollectionEnabled: false }
150150
);
151151
expect(() =>
152152
initializeApp(
153153
{
154154
apiKey: 'test1'
155155
},
156-
{ name: appName, automaticDataCollectionEnabled: false }
156+
{ name: appName, automaticDataCollectionEnabled: true }
157157
)
158158
).throws(/'MyApp'.*exists/i);
159159
});
@@ -164,11 +164,16 @@ describe('API tests', () => {
164164
expect(app.name).to.equal(appName);
165165
});
166166

167-
it('sets automaticDataCollectionEnabled', () => {
168-
const app = initializeApp({}, { automaticDataCollectionEnabled: true });
167+
it('sets automaticDataCollectionEnabled to true by default', () => {
168+
const app = initializeApp({});
169169
expect(app.automaticDataCollectionEnabled).to.be.true;
170170
});
171171

172+
it('sets a new automaticDataCollectionEnabled value if provided', () => {
173+
const app = initializeApp({}, { automaticDataCollectionEnabled: false });
174+
expect(app.automaticDataCollectionEnabled).to.be.false;
175+
});
176+
172177
it('adds registered components to App', () => {
173178
_clearComponents();
174179
const comp1 = createTestComponent('test1');
@@ -211,7 +216,7 @@ describe('API tests', () => {
211216

212217
const app = initializeServerApp(options, serverAppSettings);
213218
expect(app).to.not.equal(null);
214-
expect(app.automaticDataCollectionEnabled).to.be.false;
219+
expect(app.automaticDataCollectionEnabled).to.be.true;
215220
await deleteApp(app);
216221
expect((app as FirebaseServerAppImpl).isDeleted).to.be.true;
217222
});

packages/app/src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export function initializeApp(
143143

144144
const config: Required<FirebaseAppSettings> = {
145145
name: DEFAULT_ENTRY_NAME,
146-
automaticDataCollectionEnabled: false,
146+
automaticDataCollectionEnabled: true,
147147
...rawConfig
148148
};
149149
const name = config.name;
@@ -241,7 +241,7 @@ export function initializeServerApp(
241241
}
242242

243243
if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
244-
_serverAppConfig.automaticDataCollectionEnabled = false;
244+
_serverAppConfig.automaticDataCollectionEnabled = true;
245245
}
246246

247247
let appOptions: FirebaseOptions;

packages/app/src/firebaseApp.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ describe('FirebaseAppNext', () => {
2727
};
2828
const app = new FirebaseAppImpl(
2929
options,
30-
{ name: 'test', automaticDataCollectionEnabled: false },
30+
{ name: 'test', automaticDataCollectionEnabled: true },
3131
new ComponentContainer('test')
3232
);
3333

34-
expect(app.automaticDataCollectionEnabled).to.be.false;
34+
expect(app.automaticDataCollectionEnabled).to.be.true;
3535
expect(app.name).to.equal('test');
3636
expect(app.options).to.deep.equal(options);
3737
});

packages/app/src/firebaseServerApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class FirebaseServerAppImpl
7474
const automaticDataCollectionEnabled =
7575
serverConfig.automaticDataCollectionEnabled !== undefined
7676
? serverConfig.automaticDataCollectionEnabled
77-
: false;
77+
: true;
7878

7979
// Create the FirebaseAppSettings object for the FirebaseAppImp constructor.
8080
const config: Required<FirebaseAppSettings> = {

packages/app/src/public-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface FirebaseAppSettings {
165165
*/
166166
name?: string;
167167
/**
168-
* The settable config flag for GDPR opt-in/opt-out
168+
* The settable config flag for GDPR opt-in/opt-out. Defaults to true.
169169
*/
170170
automaticDataCollectionEnabled?: boolean;
171171
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Endpoint } from '../../api';
2929
import { UserInternal } from '../../model/user';
3030
import { _castAuth } from './auth_impl';
3131
import { connectAuthEmulator } from './emulator';
32+
import * as Util from '@firebase/util';
3233

3334
use(sinonChai);
3435
use(chaiAsPromised);
@@ -38,8 +39,10 @@ describe('core/auth/emulator', () => {
3839
let user: UserInternal;
3940
let normalEndpoint: fetch.Route;
4041
let emulatorEndpoint: fetch.Route;
42+
let utilStub: sinon.SinonStub;
4143

4244
beforeEach(async () => {
45+
utilStub = sinon.stub(Util, 'pingServer');
4346
auth = await testAuth();
4447
user = testUser(_castAuth(auth), 'uid', 'email', true);
4548
fetch.setUp();
@@ -154,6 +157,19 @@ describe('core/auth/emulator', () => {
154157
);
155158
}
156159
});
160+
it('calls pingServer with port if specified', () => {
161+
connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev:2020');
162+
expect(utilStub).to.have.been.calledWith(
163+
'https://abc.cloudworkstations.dev:2020'
164+
);
165+
});
166+
167+
it('calls pingServer with no port if none specified', () => {
168+
connectAuthEmulator(auth, 'https://abc.cloudworkstations.dev');
169+
expect(utilStub).to.have.been.calledWith(
170+
'https://abc.cloudworkstations.dev'
171+
);
172+
});
157173

158174
it('logs out a warning to the console', () => {
159175
sinon.stub(console, 'info');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function connectAuthEmulator(
103103

104104
// Workaround to get cookies in Firebase Studio
105105
if (isCloudWorkstation(host)) {
106-
void pingServer(`${protocol}//${host}:${port}`);
106+
void pingServer(`${protocol}//${host}${portStr}`);
107107
}
108108
}
109109

0 commit comments

Comments
 (0)