diff --git a/packages/realm/src/Realm.ts b/packages/realm/src/Realm.ts index 0ff8707415..ac8bf9307e 100644 --- a/packages/realm/src/Realm.ts +++ b/packages/realm/src/Realm.ts @@ -440,10 +440,8 @@ export class Realm { if (config.path || !config.sync || config.openSyncedRealmLocally) { return Realm.normalizePath(config.path); } else { - // TODO: Determine if it's okay to get the syncManager through the app instead of the user: - // return user->m_user->sync_manager()->path_for_realm(*(config.sync_config)); const bindingSyncConfig = toBindingSyncConfig(config.sync); - return config.sync.user.app.internal.syncManager.pathForRealm(bindingSyncConfig); + return config.sync.user.internal.syncManager.pathForRealm(bindingSyncConfig); } } diff --git a/packages/realm/src/app-services/SyncSession.ts b/packages/realm/src/app-services/SyncSession.ts index d9ec6c5298..976b7f48ad 100644 --- a/packages/realm/src/app-services/SyncSession.ts +++ b/packages/realm/src/app-services/SyncSession.ts @@ -211,6 +211,16 @@ type ListenerToken = { token: binding.Int64; }; +/** + * With the current properties available through Core, it it's possible to construct an app from a user nor sync session internal. + * TODO: Refactor to pass an app instance through to all places that constructs a SyncSession. + */ +const mockApp = new Proxy({} as App, { + get() { + throw new Error("Using user.app of a user returned through syncSession.config is not supported"); + }, +}); + /** * Progress listeners are shared across instances of the SyncSession, making it possible to deregister a listener on another session * TODO: Consider adding a check to verify that the callback is removed from the correct SyncSession (although that would break the API) @@ -272,9 +282,10 @@ export class SyncSession { this._internal = null; } - // TODO: Return the `error_handler` and `custom_http_headers` + // TODO: Return the `error_handler` + // TODO: Figure out a way to avoid passing a mocked app instance when constructing the User. get config(): SyncConfiguration { - const user = new User(this.internal.user, {} as unknown as App); + const user = new User(this.internal.user, mockApp); const { partitionValue, flxSyncRequested, customHttpHeaders } = this.internal.config; if (flxSyncRequested) { return { user, flexible: true, customHttpHeaders };