Skip to content

Commit 41465ec

Browse files
committed
AV.User._currentUserDisabled 更名 AV._config.disableCurrentUser,由 init 初始化该配置项
1 parent 7e85bdc commit 41465ec

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/user.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module.exports = function(AV) {
9696

9797
_handleSaveResult: function(makeCurrent) {
9898
// Clean up and synchronize the authData object, removing any unset values
99-
if (makeCurrent && !AV.User._currentUserDisabled) {
99+
if (makeCurrent && !AV._config.disableCurrentUser) {
100100
this._isCurrentUser = true;
101101
}
102102
this._cleanupAuthData();
@@ -105,7 +105,7 @@ module.exports = function(AV) {
105105
delete this._serverData.password;
106106
this._rebuildEstimatedDataForKey("password");
107107
this._refreshCache();
108-
if ((makeCurrent || this.isCurrent()) && !AV.User._currentUserDisabled) {
108+
if ((makeCurrent || this.isCurrent()) && !AV._config.disableCurrentUser) {
109109
// Some old version of leanengine-node-sdk will overwrite
110110
// AV.User._saveCurrentUser which returns no Promise.
111111
// So we need a Promise wrapper.
@@ -606,8 +606,6 @@ module.exports = function(AV) {
606606
// The mapping of auth provider names to actual providers
607607
_authProviders: {},
608608

609-
_currentUserDisabled: false,
610-
611609
// Class Methods
612610

613611
/**
@@ -797,7 +795,7 @@ module.exports = function(AV) {
797795
* <code>current</code> will return <code>null</code>.
798796
*/
799797
logOut: function() {
800-
if (AV.User._currentUserDisabled) {
798+
if (AV._config.disableCurrentUser) {
801799
return console.warn('AV.User\'s currentUser disabled, use User#logOut instead');
802800
}
803801

@@ -978,7 +976,7 @@ module.exports = function(AV) {
978976
* @return {AV.Promise} resolved with the currently logged in AV.User.
979977
*/
980978
currentAsync: function() {
981-
if (AV.User._currentUserDisabled) {
979+
if (AV._config.disableCurrentUser) {
982980
console.warn('AV.User\'s currentUser disabled, access user from request instead');
983981
return AV.Promise.as(null);
984982
}
@@ -1027,7 +1025,7 @@ module.exports = function(AV) {
10271025
* @return {AV.Object} The currently logged in AV.User.
10281026
*/
10291027
current: function() {
1030-
if (AV.User._currentUserDisabled) {
1028+
if (AV._config.disableCurrentUser) {
10311029
console.warn('AV.User\'s currentUser disabled, access user from request instead');
10321030
return null;
10331031
}
@@ -1067,10 +1065,6 @@ module.exports = function(AV) {
10671065
return AV.User._currentUser;
10681066
},
10691067

1070-
disableCurrentUser: function() {
1071-
AV.User._currentUserDisabled = true;
1072-
},
1073-
10741068
/**
10751069
* Persists a user as currentUser to localStorage, and into the singleton.
10761070
*/

src/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ const init = (AV) => {
2828
APIServerURL: AVConfig.APIServerURL || '',
2929

3030
// 当前是否为 nodejs 环境
31-
isNode: false
31+
isNode: false,
32+
33+
// 禁用 currentUser,通常用于多用户环境
34+
disableCurrentUser: false
3235
});
3336

3437
/**
@@ -154,6 +157,7 @@ const init = (AV) => {
154157
}
155158
initialize(options.appId, options.appKey, options.masterKey);
156159
setRegionServer(options.region);
160+
AVConfig.disableCurrentUser = options.disableCurrentUser;
157161
} else {
158162
throw new Error('AV.init(): Parameter is not correct.');
159163
}
@@ -393,7 +397,7 @@ const init = (AV) => {
393397
// Pass the session token
394398
if (sessionToken) {
395399
dataObject._SessionToken = sessionToken;
396-
} else if (!AV.User._currentUserDisabled) {
400+
} else if (!AV._config.disableCurrentUser) {
397401
return AV.User.currentAsync().then(function(currentUser) {
398402
if (currentUser && currentUser._sessionToken) {
399403
dataObject._SessionToken = currentUser._sessionToken;
@@ -402,7 +406,7 @@ const init = (AV) => {
402406
}
403407
}).then(function() {
404408
// Pass the installation id
405-
if (!AV.User._currentUserDisabled) {
409+
if (!AV._config.disableCurrentUser) {
406410
return AV._getInstallationId().then(function(installationId) {
407411
dataObject._InstallationId = installationId;
408412
});

test/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe("User", function() {
288288
before(function() {
289289
originalUser = AV.User._currentUser;
290290
AV.User._currentUser = null;
291-
AV.User._currentUserDisabled = true;
291+
AV._config.disableCurrentUser = true;
292292
AV._useMasterKey = false;
293293
});
294294

@@ -343,7 +343,7 @@ describe("User", function() {
343343
});
344344

345345
after(function() {
346-
AV.User._currentUserDisabled = false;
346+
AV._config.disableCurrentUser = false;
347347
AV._useMasterKey = true;
348348
AV.User._currentUser = originalUser;
349349
});

0 commit comments

Comments
 (0)