Skip to content

Commit 5decaec

Browse files
committed
Merge pull request #1072 from ParsePlatform/fosco.user-cache
Clear the session-user cache when changing _User objects
2 parents e2bcc87 + 877d29d commit 5decaec

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
@@ -342,6 +342,11 @@ RestWrite.prototype.transformUser = function() {
342342
});
343343
}
344344

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

0 commit comments

Comments
 (0)