Skip to content

Commit

Permalink
fix(TopBarProfileMenu): use window.location.reload on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
znarf committed May 15, 2018
1 parent 3eb5017 commit 8df0e07
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/components/TopBarProfileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,15 @@ class TopBarProfileMenu extends React.Component {
super(props);
this.state = { showProfileMenu: false, loading: true };
this.toggleProfileMenu = this.toggleProfileMenu.bind(this);
this.logout = this.logout.bind(this);
this.messages = defineMessages({
'tooltip.balance': { id: 'profilemenu.memberships.tooltip.balance', defaultMessage: 'Balance {balance}' },
'tooltip.pendingExpenses': { id: 'profilemenu.memberships.tooltip.pendingExpenses', defaultMessage: '{n} pending expenses' },
'menu.transactions': { id: 'menu.transactions', defaultMessage: 'transactions' }
});
}

logout() {
this.setState({ showProfileMenu: false, status: 'loggingout' })
window.localStorage.removeItem('accessToken');
window.localStorage.removeItem('LoggedInUser');
window.location.replace(window.location.href);
}

componentDidMount() {
this.onClickOutsideRef = this.onClickOutside.bind(this);
document.addEventListener('click', this.onClickOutsideRef);
document.addEventListener('click', this.onClickOutside);
if (typeof window !== 'undefined') {
this.redirectAfterSignin = window.location.href.replace(/^https?:\/\/[^/]+/,'');
if (!window.localStorage.accessToken) {
Expand All @@ -44,10 +35,17 @@ class TopBarProfileMenu extends React.Component {
}

componentWillUnmount() {
document.removeEventListener('click', this.onClickOutsideRef);
document.removeEventListener('click', this.onClickOutside);
}

logout = () => {
this.setState({ showProfileMenu: false, status: 'loggingout' })
window.localStorage.removeItem('accessToken');
window.localStorage.removeItem('LoggedInUser');
window.location.reload();
}

onClickOutside() {
onClickOutside = () => {
this.setState({ showProfileMenu: false });
}

Expand Down

0 comments on commit 8df0e07

Please sign in to comment.