Skip to content

Commit 9f6e691

Browse files
committed
skip user session lookup in node environment
1 parent 329ab41 commit 9f6e691

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/db/src/impl/pouch/PouchDataLayerProvider.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,32 @@ export class PouchDataLayerProvider implements DataLayerProvider {
2727
async initialize(): Promise<void> {
2828
if (this.initialized) return;
2929

30-
// Get the current username from session
31-
this.currentUsername = await getLoggedInUsername();
32-
33-
// Create the user db instance
34-
if (this.currentUsername) {
35-
this.userDB = await User.instance(this.currentUsername);
30+
// Check if we are in a Node.js environment
31+
const isNodeEnvironment =
32+
typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
33+
34+
if (isNodeEnvironment) {
35+
console.log(
36+
'PouchDataLayerProvider: Running in Node.js environment, skipping user session check and user DB initialization.'
37+
);
38+
} else {
39+
// Assume browser-like environment, proceed with user session logic
40+
try {
41+
// Get the current username from session
42+
this.currentUsername = await getLoggedInUsername();
43+
44+
// Create the user db instance if a username was found
45+
if (this.currentUsername) {
46+
this.userDB = await User.instance(this.currentUsername);
47+
} else {
48+
console.warn('PouchDataLayerProvider: No logged-in username found in session.');
49+
}
50+
} catch (error) {
51+
console.error(
52+
'PouchDataLayerProvider: Error during user session check or user DB initialization:',
53+
error
54+
);
55+
}
3656
}
3757

3858
this.initialized = true;

0 commit comments

Comments
 (0)