@peers-app/peers-sdk 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,6 +32,14 @@ async function getUserContext() {
|
|
|
32
32
|
}
|
|
33
33
|
function setUserContext(userContext) {
|
|
34
34
|
if (userContextInstance) {
|
|
35
|
+
if (typeof window !== 'undefined') {
|
|
36
|
+
// In a browser/PWA context the module singleton persists across navigations
|
|
37
|
+
// and HMR re-runs. Allow replacing it — the new context is authoritative.
|
|
38
|
+
userContextInstance = userContext;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
window.userContext = userContext;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
35
43
|
throw new Error(`Cannot set user context again after it has already been set`);
|
|
36
44
|
}
|
|
37
45
|
userContextInstance = userContext;
|
|
@@ -55,6 +63,12 @@ function getTableContainer(dataContext) {
|
|
|
55
63
|
return dataContext.tableContainer;
|
|
56
64
|
}
|
|
57
65
|
function setDefaultClientUserContext(userId) {
|
|
66
|
+
// If a real (server-side) user context is already set in the same process
|
|
67
|
+
// (e.g. PWA where peers-device runs in the browser), don't overwrite it
|
|
68
|
+
// with a client proxy — the real context already handles tableMethodCall directly.
|
|
69
|
+
if (userContextInstance) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
58
72
|
const clientProxyDataSourceFactory = (metaData, schema, groupId) => {
|
|
59
73
|
return new client_proxy_data_source_1.ClientProxyDataSource(metaData, schema, groupId || userId);
|
|
60
74
|
};
|