Skip to content

Commit 93f707e

Browse files
committed
feat: allow reinitializing
1 parent 5a0280c commit 93f707e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/init.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function getDefaultServerURLs(appId) {
2929
}
3030

3131
let _disableAppRouter = false;
32+
let _initialized = false;
3233

3334
/**
3435
* URLs for services
@@ -71,7 +72,10 @@ AV.init = function init(options, ...params) {
7172
production,
7273
realtime,
7374
} = options;
74-
if (AV.applicationId) throw new Error('SDK is already initialized.');
75+
if (_initialized)
76+
console.warn(
77+
'Initializing LeanCloud Storage SDK which has already been initialized. Reinitializing the SDK might cause problems like unexpected cross-app data writing and invalid relations.'
78+
);
7579
if (!appId) throw new TypeError('appId must be a string');
7680
if (!appKey) throw new TypeError('appKey must be a string');
7781
if (process.env.CLIENT_PLATFORM && masterKey)
@@ -117,6 +121,7 @@ AV.init = function init(options, ...params) {
117121
},
118122
});
119123
}
124+
_initialized = true;
120125
};
121126

122127
// If we're running in node.js, allow using the master key.

0 commit comments

Comments
 (0)