Skip to content

Commit d1064a8

Browse files
Fix Component Provider
1 parent cad6dc5 commit d1064a8

File tree

4 files changed

+202
-75
lines changed

4 files changed

+202
-75
lines changed

packages/firestore/exp/src/api/components.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,7 @@ export function initializeFirestoreClient(
138138
'any other methods on a Firestore object.'
139139
);
140140
}
141-
142-
const settings = firestore._getSettings();
143-
const databaseInfo = new DatabaseInfo(
144-
firestore._databaseId,
145-
firestore._persistenceKey,
146-
settings.host ?? DEFAULT_HOST,
147-
settings.ssl ?? DEFAULT_SSL,
148-
/** forceLongPolling= */ false
149-
);
141+
const databaseInfo = firestore._getDatabaseInfo();
150142
const firestoreClient = new FirestoreClient(
151143
firestore._credentials,
152144
firestore._queue
@@ -189,20 +181,11 @@ export async function setComponentProviders(
189181
offlineComponentProvider: OfflineComponentProvider,
190182
onlineComponentProvider: OnlineComponentProvider
191183
): Promise<void> {
192-
// TODO: Move this to Firestore
193-
const componentConfiguration = {
194-
asyncQueue: firestore._queue,
195-
databaseInfo: firestore._databaseId,
196-
clientId: null as any,
197-
credentials: null as any,
198-
initialUser: null as any,
199-
maxConcurrentLimboResolutions: null as any,
200-
persistenceSettings: null as any
201-
};
202-
await offlineComponentProvider.initialize(componentConfiguration as any);
184+
const componentConfiguration = firestore._getConfiguration();
185+
await offlineComponentProvider.initialize(componentConfiguration);
203186
await onlineComponentProvider.initialize(
204187
offlineComponentProvider,
205-
componentConfiguration as any
188+
componentConfiguration
206189
);
207190
offlineComponentProviders.set(firestore, offlineComponentProvider);
208191
onlineComponentProviders.set(firestore, onlineComponentProvider);

packages/firestore/exp/src/api/database.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ import {
4141
setComponentProviders
4242
} from './components';
4343
import {
44+
ComponentConfiguration,
4445
IndexedDbOfflineComponentProvider,
4546
MultiTabOfflineComponentProvider,
4647
MultiTabOnlineComponentProvider,
4748
OnlineComponentProvider
4849
} from '../../../src/core/component_provider';
50+
import { MAX_CONCURRENT_LIMBO_RESOLUTIONS } from '../../../src/core/firestore_client';
51+
import { DatabaseInfo } from '../../../src/core/database_info';
52+
import { DEFAULT_HOST, DEFAULT_SSL } from '../../../lite/src/api/components';
53+
import { User } from '../../../src/auth/user';
54+
import { AutoId } from '../../../src/util/misc';
4955

5056
/**
5157
* The root reference to the Firestore database and the entry point for the
@@ -55,6 +61,10 @@ export class Firestore extends LiteFirestore
5561
implements firestore.FirebaseFirestore, _FirebaseService {
5662
readonly _queue = new AsyncQueue();
5763
readonly _persistenceKey: string;
64+
// TODO(firestoreexp): Support user change without SyncEning
65+
private _initialUser: User = User.UNAUTHENTICATED;
66+
67+
private readonly _clientId = AutoId.newId();
5868

5969
// We override the Settings property of the Lite SDK since the full Firestore
6070
// SDK supports more settings.
@@ -66,6 +76,34 @@ export class Firestore extends LiteFirestore
6676
) {
6777
super(app, authProvider);
6878
this._persistenceKey = app.name;
79+
80+
this._credentials.getToken().then(token => {
81+
if (token) {
82+
this._initialUser = token.user;
83+
}
84+
});
85+
}
86+
87+
_getDatabaseInfo(): DatabaseInfo {
88+
const settings = this._getSettings();
89+
return new DatabaseInfo(
90+
this._databaseId,
91+
this._persistenceKey,
92+
settings.host ?? DEFAULT_HOST,
93+
settings.ssl ?? DEFAULT_SSL,
94+
/** forceLongPolling= */ false
95+
);
96+
}
97+
_getConfiguration(): ComponentConfiguration {
98+
return {
99+
asyncQueue: this._queue,
100+
databaseInfo: this._getDatabaseInfo(),
101+
clientId: this._clientId,
102+
credentials: this._credentials,
103+
initialUser: this._initialUser,
104+
maxConcurrentLimboResolutions: MAX_CONCURRENT_LIMBO_RESOLUTIONS,
105+
persistenceSettings: { durable: false }
106+
};
69107
}
70108

71109
_getSettings(): firestore.Settings {

0 commit comments

Comments
 (0)