Skip to content

Commit

Permalink
Merge branch 'master' into ss-use-emulator-firestore
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Oct 16, 2020
2 parents 1aace02 + 8939aec commit fe8f6bb
Show file tree
Hide file tree
Showing 69 changed files with 674 additions and 1,322 deletions.
1 change: 0 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@firebase/installations-types-exp",
"@firebase/performance-exp",
"@firebase/performance-types-exp",
"@firebase/testing",
"firebase-exp",
"@firebase/app-compat",
"@firebase/changelog-generator",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/great-rice-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"firebase": major
"@firebase/firestore": major
---

Removed the undocumented `Firestore.logLevel` property.
6 changes: 6 additions & 0 deletions .changeset/shy-trees-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"firebase": major
"@firebase/firestore": major
---

Removed depreacted `experimentalTabSynchronization` settings. To enable multi-tab sychronization, use `synchronizeTabs` instead.
7 changes: 7 additions & 0 deletions .changeset/strange-rabbits-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'firebase': major
'@firebase/firestore': major
'@firebase/firestore-types': major
---

Removed the `timestampsInSnapshots` option from `FirestoreSettings`. Now, Firestore always returns `Timestamp` values for all timestamp values.
2 changes: 1 addition & 1 deletion .github/workflows/test-changed-misc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test rxFire, @firebase/testing and @firebase/rules-unit-testing
name: Test rxFire and @firebase/rules-unit-testing

on: pull_request

Expand Down
78 changes: 78 additions & 0 deletions packages-exp/auth-compat-exp/src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { FirebaseApp } from '@firebase/app-types';
import * as impl from '@firebase/auth-exp/internal';
import { Config } from '@firebase/auth-types-exp';
import { expect, use } from 'chai';
import * as sinon from 'sinon';
import * as sinonChai from 'sinon-chai';
import { Auth } from './auth';

use(sinonChai);

// For the most part, the auth methods just call straight through. Some parts
// of the auth compat layer are more complicated: these tests cover those
describe('auth compat', () => {
context('redirect persistence key storage', () => {
let underlyingAuth: impl.AuthImpl;
let app: FirebaseApp;
beforeEach(() => {
app = { options: { apiKey: 'api-key' } } as FirebaseApp;
underlyingAuth = new impl.AuthImpl(app, {
apiKey: 'api-key'
} as Config);
sinon.stub(underlyingAuth, '_initializeWithPersistence');
});

afterEach(() => {
sinon.restore;
});

it('saves the persistence into session storage if available', () => {
const authCompat = new Auth(app, underlyingAuth);
if (typeof self !== 'undefined') {
sinon.stub(underlyingAuth, '_getPersistence').returns('TEST');
// eslint-disable-next-line @typescript-eslint/no-floating-promises
authCompat.signInWithRedirect(new impl.GoogleAuthProvider('google'));
expect(
sessionStorage.getItem('firebase:persistence:api-key:undefined')
).to.eq('TEST');
}
});

it('pulls the persistence and sets as the main persitsence if set', () => {
if (typeof self !== 'undefined') {
sessionStorage.setItem(
'firebase:persistence:api-key:undefined',
'NONE'
);
new Auth(app, underlyingAuth);
// eslint-disable-next-line @typescript-eslint/no-floating-promises
expect(
underlyingAuth._initializeWithPersistence
).to.have.been.calledWith(
[
impl._getInstance(impl.inMemoryPersistence),
impl._getInstance(impl.indexedDBLocalPersistence)
],
impl.browserPopupRedirectResolver
);
}
});
});
});
57 changes: 54 additions & 3 deletions packages-exp/auth-compat-exp/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
} from './user_credential';
import { unwrap, Wrapper } from './wrap';

const PERSISTENCE_KEY = 'persistence';

export class Auth
implements compat.FirebaseAuth, Wrapper<externs.Auth>, _FirebaseService {
// private readonly auth: impl.AuthImpl;
Expand All @@ -46,10 +48,15 @@ export class Auth
return;
}

// Note this is slightly different behavior: in this case, the stored
// persistence is checked *first* rather than last. This is because we want
// the fallback (if no user is found) to be the stored persistence type
const storedPersistence = this.getPersistenceFromRedirect();
const persistences = storedPersistence ? [storedPersistence] : [];
persistences.push(impl.indexedDBLocalPersistence);

// TODO(avolkovi): Implement proper persistence fallback
const hierarchy = [impl.indexedDBLocalPersistence].map<impl.Persistence>(
impl._getInstance
);
const hierarchy = persistences.map<impl.Persistence>(impl._getInstance);

// TODO: platform needs to be determined using heuristics
impl.assertFn(apiKey, impl.AuthErrorCode.INVALID_API_KEY, {
Expand Down Expand Up @@ -279,6 +286,7 @@ export class Auth
impl.AuthErrorCode.OPERATION_NOT_SUPPORTED,
{ appName: this.app.name }
);
this.savePersistenceForRedirect();
return impl.signInWithRedirect(
this.auth,
provider as externs.AuthProvider,
Expand All @@ -297,6 +305,49 @@ export class Auth
_delete(): Promise<void> {
return this.auth._delete();
}

private savePersistenceForRedirect(): void {
const win = getSelfWindow();
const key = impl._persistenceKeyName(
PERSISTENCE_KEY,
this.auth.config.apiKey,
this.auth.name
);
if (win?.sessionStorage) {
win.sessionStorage.setItem(key, this.auth._getPersistence());
}
}

private getPersistenceFromRedirect(): externs.Persistence | null {
const win = getSelfWindow();
if (!win?.sessionStorage) {
return null;
}

const key = impl._persistenceKeyName(
PERSISTENCE_KEY,
this.auth.config.apiKey,
this.auth.name
);
const persistence = win.sessionStorage.getItem(key);

switch (persistence) {
case impl.inMemoryPersistence.type:
return impl.inMemoryPersistence;
case impl.indexedDBLocalPersistence.type:
return impl.indexedDBLocalPersistence;
case impl.browserSessionPersistence.type:
return impl.browserSessionPersistence;
case impl.browserLocalPersistence.type:
return impl.browserLocalPersistence;
default:
return null;
}
}
}

function getSelfWindow(): Window | null {
return typeof window !== 'undefined' ? window : null;
}

function wrapObservers(
Expand Down
22 changes: 0 additions & 22 deletions packages-exp/auth-compat-exp/src/index.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages-exp/auth-exp/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { assert } from '../src/core/util/assert';
export { SignInWithIdpResponse } from '../src/api/authentication/idp';
export { AuthErrorCode } from '../src/core/errors';
export { Persistence } from '../src/core/persistence';
export { _persistenceKeyName } from '../src/core/persistence/persistence_user_manager';
export { UserImpl } from '../src/core/user/user_impl';
export { _getInstance } from '../src/core/util/instantiator';
export { UserCredential, UserParameters } from '../src/model/user';
Expand Down
Loading

0 comments on commit fe8f6bb

Please sign in to comment.