Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/ParseUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,19 @@ export default class ParseUser extends ParseObject {
});
}

/**
* Wrap the default destroy behavior with functionality that logs out
* the current user when it is destroyed
*/
destroy(...args: Array<any>): ParsePromise {
return super.destroy.apply(this, args).then(() => {
if (this.isCurrent()) {
return CoreManager.getUserController().removeUserFromDisk();
}
return this;
});
}

/**
* Wrap the default fetch behavior with functionality to save to local
* storage if this is current user.
Expand Down Expand Up @@ -750,6 +763,13 @@ var DefaultController = {
});
},

removeUserFromDisk() {
let path = Storage.generatePath(CURRENT_USER_KEY);
currentUserCacheMatchesDisk = true;
currentUserCache = null;
return Storage.removeItemAsync(path);
},

setCurrentUser(user) {
currentUserCache = user;
user._cleanupAuthData();
Expand Down
31 changes: 31 additions & 0 deletions src/__tests__/ParseUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,37 @@ describe('ParseUser', () => {
});
}));

it('removes the current user from disk when destroyed', asyncHelper((done) => {
ParseUser.enableUnsafeCurrentUser();
ParseUser._clearCache();
Storage._clear();
CoreManager.setRESTController({
request() {
return ParsePromise.as({
objectId: 'uid9',
}, 201);
},
ajax() {}
});

ParseUser.signUp('destroyed', 'password').then((u) => {
expect(u.isCurrent()).toBe(true);
CoreManager.setRESTController({
request() {
return ParsePromise.as({}, 200);
},
ajax() {}
});
return u.destroy();
}).then((u) => {
expect(ParseUser.current()).toBe(null);
return ParseUser.currentAsync();
}).then((current) => {
expect(current).toBe(null);
done();
});
}));

it('updates the current user on disk when fetched', asyncHelper((done) => {
ParseUser.enableUnsafeCurrentUser();
ParseUser._clearCache();
Expand Down