Skip to content

Commit 877d29d

Browse files
committed
Clear the session-user cache when changing _User objects
1 parent 40812e2 commit 877d29d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

spec/ParseUser.spec.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,5 +2050,27 @@ describe('Parse.User testing', () => {
20502050
Parse.Cloud._removeHook('Triggers', 'afterSave', '_User');
20512051
done();
20522052
});
2053-
})
2053+
});
2054+
2055+
it('changes to a user should update the cache', (done) => {
2056+
Parse.Cloud.define('testUpdatedUser', (req, res) => {
2057+
expect(req.user.get('han')).toEqual('solo');
2058+
res.success({});
2059+
});
2060+
let user = new Parse.User();
2061+
user.setUsername('harrison');
2062+
user.setPassword('ford');
2063+
user.signUp().then(() => {
2064+
user.set('han', 'solo');
2065+
return user.save();
2066+
}).then(() => {
2067+
return Parse.Cloud.run('testUpdatedUser');
2068+
}).then(() => {
2069+
done();
2070+
}, (e) => {
2071+
fail('Should not have failed.');
2072+
done();
2073+
});
2074+
2075+
});
20542076
});

src/RestWrite.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ RestWrite.prototype.transformUser = function() {
341341
});
342342
}
343343

344+
// If we're updating a _User object, clear the user cache for the session
345+
if (this.query && this.auth.user && this.auth.user.getSessionToken()) {
346+
cache.users.remove(this.auth.user.getSessionToken());
347+
}
348+
344349
return promise.then(() => {
345350
// Transform the password
346351
if (!this.data.password) {

0 commit comments

Comments
 (0)