diff --git a/src/stores/LifecycleStore.js b/src/stores/LifecycleStore.js index 3ed2e5c045..d38138b3ef 100644 --- a/src/stores/LifecycleStore.js +++ b/src/stores/LifecycleStore.js @@ -16,6 +16,10 @@ limitations under the License. import dis from '../dispatcher'; import {Store} from 'flux/utils'; +const INITIAL_STATE = { + deferred_action: null, +}; + /** * A class for storing application state to do with login/registration. This is a simple * flux store that listens for actions and updates its state accordingly, informing any @@ -26,9 +30,7 @@ class LifecycleStore extends Store { super(dis); // Initialise state - this._state = { - deferred_action: null, - }; + this._state = INITIAL_STATE; } _setState(newState) { @@ -54,8 +56,15 @@ class LifecycleStore extends Store { }); dis.dispatch(deferredAction); break; + case 'on_logged_out': + this.reset(); + break; } } + + reset() { + this._state = Object.assign({}, INITIAL_STATE); + } } let singletonLifecycleStore = null; diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index 1ceef551a8..d893318af7 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -73,6 +73,9 @@ class RoomViewStore extends Store { case 'join_room': this._joinRoom(payload); break; + case 'on_logged_out': + this.reset(); + break; } } diff --git a/src/stores/SessionStore.js b/src/stores/SessionStore.js index 2fd35ce40a..62868e4fe4 100644 --- a/src/stores/SessionStore.js +++ b/src/stores/SessionStore.js @@ -16,6 +16,10 @@ limitations under the License. import dis from '../dispatcher'; import {Store} from 'flux/utils'; +const INITIAL_STATE = { + cachedPassword: localStorage.getItem('mx_pass'), +}; + /** * A class for storing application state to do with the session. This is a simple flux * store that listens for actions and updates its state accordingly, informing any @@ -33,9 +37,7 @@ class SessionStore extends Store { super(dis); // Initialise state - this._state = { - cachedPassword: localStorage.getItem('mx_pass'), - }; + this._state = INITIAL_STATE; } _update() { @@ -66,9 +68,16 @@ class SessionStore extends Store { cachedPassword: null, }); break; + case 'on_logged_out': + this.reset(); + break; } } + reset() { + this._state = Object.assign({}, INITIAL_STATE); + } + getCachedPassword() { return this._state.cachedPassword; }