Merge pull request #1072 from ParsePlatform/fosco.user-cache

Clear the session-user cache when changing _User objects
This commit is contained in:
Fosco Marotto
2016-03-18 08:51:51 -08:00
2 changed files with 28 additions and 1 deletions

View File

@@ -2050,5 +2050,27 @@ describe('Parse.User testing', () => {
Parse.Cloud._removeHook('Triggers', 'afterSave', '_User');
done();
});
})
});
it('changes to a user should update the cache', (done) => {
Parse.Cloud.define('testUpdatedUser', (req, res) => {
expect(req.user.get('han')).toEqual('solo');
res.success({});
});
let user = new Parse.User();
user.setUsername('harrison');
user.setPassword('ford');
user.signUp().then(() => {
user.set('han', 'solo');
return user.save();
}).then(() => {
return Parse.Cloud.run('testUpdatedUser');
}).then(() => {
done();
}, (e) => {
fail('Should not have failed.');
done();
});
});
});

View File

@@ -342,6 +342,11 @@ RestWrite.prototype.transformUser = function() {
});
}
// If we're updating a _User object, clear the user cache for the session
if (this.query && this.auth.user && this.auth.user.getSessionToken()) {
cache.users.remove(this.auth.user.getSessionToken());
}
return promise.then(() => {
// Transform the password
if (!this.data.password) {