Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 53ebc8d

Browse files
authored
Merge pull request #983 from matrix-org/rav/clear_storage_on_logout
Call MatrixClient.clearStores on logout
2 parents ecbc724 + c3d37c1 commit 53ebc8d

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/Lifecycle.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function _handleRestoreFailure(e) {
237237
+ ' This is a once off; sorry for the inconvenience.',
238238
);
239239

240-
_clearLocalStorage();
240+
_clearStorage();
241241

242242
return q.reject(new Error(
243243
_t('Unable to restore previous session') + ': ' + msg,
@@ -258,7 +258,7 @@ function _handleRestoreFailure(e) {
258258
return def.promise.then((success) => {
259259
if (success) {
260260
// user clicked continue.
261-
_clearLocalStorage();
261+
_clearStorage();
262262
return false;
263263
}
264264

@@ -332,6 +332,10 @@ export function setLoggedIn(credentials) {
332332
}
333333

334334
// stop any running clients before we create a new one with these new credentials
335+
//
336+
// XXX: why do we have any running clients here? Maybe on sign-in after
337+
// initial use as a guest? but what about our persistent storage? we need to
338+
// be careful not to leak e2e data created as one user into another session.
335339
stopMatrixClient();
336340

337341
MatrixClientPeg.replaceUsingCreds(credentials);
@@ -402,13 +406,19 @@ export function startMatrixClient() {
402406
* a session has been logged out / ended.
403407
*/
404408
export function onLoggedOut() {
405-
_clearLocalStorage();
406-
stopMatrixClient();
409+
stopMatrixClient(true);
407410
dis.dispatch({action: 'on_logged_out'});
408411
}
409412

410-
function _clearLocalStorage() {
413+
function _clearStorage() {
411414
Analytics.logout();
415+
416+
const cli = MatrixClientPeg.get();
417+
if (cli) {
418+
// TODO: *really* ought to wait for the promise to complete
419+
cli.clearStores().done();
420+
}
421+
412422
if (!window.localStorage) {
413423
return;
414424
}
@@ -425,9 +435,13 @@ function _clearLocalStorage() {
425435
}
426436

427437
/**
428-
* Stop all the background processes related to the current client
438+
* Stop all the background processes related to the current client.
439+
*
440+
* Optionally clears persistent stores.
441+
*
442+
* @param {boolean} clearStores true to clear the persistent stores.
429443
*/
430-
export function stopMatrixClient() {
444+
export function stopMatrixClient(clearStores) {
431445
Notifier.stop();
432446
UserActivity.stop();
433447
Presence.stop();
@@ -436,7 +450,13 @@ export function stopMatrixClient() {
436450
if (cli) {
437451
cli.stopClient();
438452
cli.removeAllListeners();
439-
cli.store.deleteAllData();
440-
MatrixClientPeg.unset();
441453
}
454+
455+
if (clearStores) {
456+
// note that we have to do this *after* stopping the client, but
457+
// *before* clearing the MatrixClientPeg.
458+
_clearStorage();
459+
}
460+
461+
MatrixClientPeg.unset();
442462
}

src/components/structures/MatrixChat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ module.exports = React.createClass({
292292
},
293293

294294
componentWillUnmount: function() {
295-
Lifecycle.stopMatrixClient();
295+
Lifecycle.stopMatrixClient(false);
296296
dis.unregister(this.dispatcherRef);
297297
UDEHandler.stopListening();
298298
window.removeEventListener("focus", this.onFocus);
@@ -364,7 +364,7 @@ module.exports = React.createClass({
364364
// is completed in another browser, we'll be 401ed for using
365365
// a guest access token for a non-guest account.
366366
// It will be restarted in onReturnToGuestClick
367-
Lifecycle.stopMatrixClient();
367+
Lifecycle.stopMatrixClient(false);
368368

369369
this.notifyNewScreen('register');
370370
break;

0 commit comments

Comments
 (0)