Skip to content

Commit e57dcb2

Browse files
committed
Merge pull request #25 from ParsePlatform/andrewi.user_server_changes
Allow login (without touching current user) on server env
2 parents 4b9d07b + 139993b commit e57dcb2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/ParseUser.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ export default class ParseUser extends ParseObject {
381381
* the login is complete.
382382
*/
383383
logIn(options: FullOptions) {
384-
if (!canUseCurrentUser) {
385-
throw new Error('It is not possible to log in on a server environment.');
386-
}
387-
388384
options = options || {};
389385

390386
var loginOptions = {};
@@ -393,7 +389,7 @@ export default class ParseUser extends ParseObject {
393389
}
394390

395391
var controller = CoreManager.getUserController();
396-
return controller.logIn(this, loginOptions)._thenRunCallbacks(options);
392+
return controller.logIn(this, loginOptions)._thenRunCallbacks(options, this);
397393
}
398394

399395
static readOnlyAttributes() {
@@ -639,7 +635,7 @@ export default class ParseUser extends ParseObject {
639635
}
640636

641637
/**
642-
* Enables the use of logIn, become, and a current user in a server
638+
* Enables the use of become or the current user in a server
643639
* environment. These features are disabled by default, since they depend on
644640
* global objects that are not memory-safe for most servers.
645641
* @method enableUnsafeCurrentUser
@@ -649,6 +645,17 @@ export default class ParseUser extends ParseObject {
649645
canUseCurrentUser = true;
650646
}
651647

648+
/**
649+
* Disables the use of become or the current user in any environment.
650+
* These features are disabled on servers by default, since they depend on
651+
* global objects that are not memory-safe for most servers.
652+
* @method disableUnsafeCurrentUser
653+
* @static
654+
*/
655+
static disableUnsafeCurrentUser() {
656+
canUseCurrentUser = false;
657+
}
658+
652659
static _registerAuthenticationProvider(provider) {
653660
authProviders[provider.getAuthType()] = provider;
654661
// Synchronize the current user with the auth provider.
@@ -818,6 +825,10 @@ var DefaultController = {
818825
);
819826
response.password = undefined;
820827
user._finishFetch(response);
828+
if (!canUseCurrentUser) {
829+
// We can't set the current user, so just return the one we logged in
830+
return ParsePromise.as(user);
831+
}
821832
return DefaultController.setCurrentUser(user);
822833
});
823834
},

src/__tests__/ParseUser-test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ describe('ParseUser', () => {
8787
});
8888

8989
it('does not allow current user actions on node servers', () => {
90-
expect(ParseUser.logIn.bind(null, 'username', 'password')).toThrow(
91-
'It is not possible to log in on a server environment.'
92-
);
9390
expect(ParseUser.become.bind(null, 'token')).toThrow(
9491
'It is not memory-safe to become a user in a server environment'
9592
);

0 commit comments

Comments
 (0)