Skip to content

Commit fe8f6bb

Browse files
authored
Merge branch 'master' into ss-use-emulator-firestore
2 parents 1aace02 + 8939aec commit fe8f6bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+674
-1322
lines changed

.changeset/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@firebase/installations-types-exp",
2222
"@firebase/performance-exp",
2323
"@firebase/performance-types-exp",
24-
"@firebase/testing",
2524
"firebase-exp",
2625
"@firebase/app-compat",
2726
"@firebase/changelog-generator",

.changeset/great-rice-smash.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"firebase": major
3+
"@firebase/firestore": major
4+
---
5+
6+
Removed the undocumented `Firestore.logLevel` property.

.changeset/shy-trees-divide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"firebase": major
3+
"@firebase/firestore": major
4+
---
5+
6+
Removed depreacted `experimentalTabSynchronization` settings. To enable multi-tab sychronization, use `synchronizeTabs` instead.

.changeset/strange-rabbits-wait.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'firebase': major
3+
'@firebase/firestore': major
4+
'@firebase/firestore-types': major
5+
---
6+
7+
Removed the `timestampsInSnapshots` option from `FirestoreSettings`. Now, Firestore always returns `Timestamp` values for all timestamp values.

.github/workflows/test-changed-misc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test rxFire, @firebase/testing and @firebase/rules-unit-testing
1+
name: Test rxFire and @firebase/rules-unit-testing
22

33
on: pull_request
44

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { FirebaseApp } from '@firebase/app-types';
19+
import * as impl from '@firebase/auth-exp/internal';
20+
import { Config } from '@firebase/auth-types-exp';
21+
import { expect, use } from 'chai';
22+
import * as sinon from 'sinon';
23+
import * as sinonChai from 'sinon-chai';
24+
import { Auth } from './auth';
25+
26+
use(sinonChai);
27+
28+
// For the most part, the auth methods just call straight through. Some parts
29+
// of the auth compat layer are more complicated: these tests cover those
30+
describe('auth compat', () => {
31+
context('redirect persistence key storage', () => {
32+
let underlyingAuth: impl.AuthImpl;
33+
let app: FirebaseApp;
34+
beforeEach(() => {
35+
app = { options: { apiKey: 'api-key' } } as FirebaseApp;
36+
underlyingAuth = new impl.AuthImpl(app, {
37+
apiKey: 'api-key'
38+
} as Config);
39+
sinon.stub(underlyingAuth, '_initializeWithPersistence');
40+
});
41+
42+
afterEach(() => {
43+
sinon.restore;
44+
});
45+
46+
it('saves the persistence into session storage if available', () => {
47+
const authCompat = new Auth(app, underlyingAuth);
48+
if (typeof self !== 'undefined') {
49+
sinon.stub(underlyingAuth, '_getPersistence').returns('TEST');
50+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
51+
authCompat.signInWithRedirect(new impl.GoogleAuthProvider('google'));
52+
expect(
53+
sessionStorage.getItem('firebase:persistence:api-key:undefined')
54+
).to.eq('TEST');
55+
}
56+
});
57+
58+
it('pulls the persistence and sets as the main persitsence if set', () => {
59+
if (typeof self !== 'undefined') {
60+
sessionStorage.setItem(
61+
'firebase:persistence:api-key:undefined',
62+
'NONE'
63+
);
64+
new Auth(app, underlyingAuth);
65+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
66+
expect(
67+
underlyingAuth._initializeWithPersistence
68+
).to.have.been.calledWith(
69+
[
70+
impl._getInstance(impl.inMemoryPersistence),
71+
impl._getInstance(impl.indexedDBLocalPersistence)
72+
],
73+
impl.browserPopupRedirectResolver
74+
);
75+
}
76+
});
77+
});
78+
});

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

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
} from './user_credential';
3737
import { unwrap, Wrapper } from './wrap';
3838

39+
const PERSISTENCE_KEY = 'persistence';
40+
3941
export class Auth
4042
implements compat.FirebaseAuth, Wrapper<externs.Auth>, _FirebaseService {
4143
// private readonly auth: impl.AuthImpl;
@@ -46,10 +48,15 @@ export class Auth
4648
return;
4749
}
4850

51+
// Note this is slightly different behavior: in this case, the stored
52+
// persistence is checked *first* rather than last. This is because we want
53+
// the fallback (if no user is found) to be the stored persistence type
54+
const storedPersistence = this.getPersistenceFromRedirect();
55+
const persistences = storedPersistence ? [storedPersistence] : [];
56+
persistences.push(impl.indexedDBLocalPersistence);
57+
4958
// TODO(avolkovi): Implement proper persistence fallback
50-
const hierarchy = [impl.indexedDBLocalPersistence].map<impl.Persistence>(
51-
impl._getInstance
52-
);
59+
const hierarchy = persistences.map<impl.Persistence>(impl._getInstance);
5360

5461
// TODO: platform needs to be determined using heuristics
5562
impl.assertFn(apiKey, impl.AuthErrorCode.INVALID_API_KEY, {
@@ -279,6 +286,7 @@ export class Auth
279286
impl.AuthErrorCode.OPERATION_NOT_SUPPORTED,
280287
{ appName: this.app.name }
281288
);
289+
this.savePersistenceForRedirect();
282290
return impl.signInWithRedirect(
283291
this.auth,
284292
provider as externs.AuthProvider,
@@ -297,6 +305,49 @@ export class Auth
297305
_delete(): Promise<void> {
298306
return this.auth._delete();
299307
}
308+
309+
private savePersistenceForRedirect(): void {
310+
const win = getSelfWindow();
311+
const key = impl._persistenceKeyName(
312+
PERSISTENCE_KEY,
313+
this.auth.config.apiKey,
314+
this.auth.name
315+
);
316+
if (win?.sessionStorage) {
317+
win.sessionStorage.setItem(key, this.auth._getPersistence());
318+
}
319+
}
320+
321+
private getPersistenceFromRedirect(): externs.Persistence | null {
322+
const win = getSelfWindow();
323+
if (!win?.sessionStorage) {
324+
return null;
325+
}
326+
327+
const key = impl._persistenceKeyName(
328+
PERSISTENCE_KEY,
329+
this.auth.config.apiKey,
330+
this.auth.name
331+
);
332+
const persistence = win.sessionStorage.getItem(key);
333+
334+
switch (persistence) {
335+
case impl.inMemoryPersistence.type:
336+
return impl.inMemoryPersistence;
337+
case impl.indexedDBLocalPersistence.type:
338+
return impl.indexedDBLocalPersistence;
339+
case impl.browserSessionPersistence.type:
340+
return impl.browserSessionPersistence;
341+
case impl.browserLocalPersistence.type:
342+
return impl.browserLocalPersistence;
343+
default:
344+
return null;
345+
}
346+
}
347+
}
348+
349+
function getSelfWindow(): Window | null {
350+
return typeof window !== 'undefined' ? window : null;
300351
}
301352

302353
function wrapObservers(

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages-exp/auth-exp/internal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { assert } from '../src/core/util/assert';
2525
export { SignInWithIdpResponse } from '../src/api/authentication/idp';
2626
export { AuthErrorCode } from '../src/core/errors';
2727
export { Persistence } from '../src/core/persistence';
28+
export { _persistenceKeyName } from '../src/core/persistence/persistence_user_manager';
2829
export { UserImpl } from '../src/core/user/user_impl';
2930
export { _getInstance } from '../src/core/util/instantiator';
3031
export { UserCredential, UserParameters } from '../src/model/user';

0 commit comments

Comments
 (0)