logout from user menu

This commit is contained in:
Chen-I Lim 2021-01-14 18:23:15 -08:00
parent 684177d5e2
commit bf8b624346
2 changed files with 22 additions and 2 deletions

View file

@ -1,12 +1,13 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useContext} from 'react'
import React from 'react'
import {FormattedMessage, injectIntl, IntlShape} from 'react-intl'
import {Archiver} from '../archiver'
import {Board, MutableBoard} from '../blocks/board'
import {BoardView, MutableBoardView} from '../blocks/boardView'
import mutator from '../mutator'
import octoClient from '../octoClient'
import {darkTheme, defaultTheme, lightTheme, setTheme} from '../theme'
import {UserContext} from '../user'
import {WorkspaceTree} from '../viewModel/workspaceTree'
@ -89,7 +90,22 @@ class Sidebar extends React.Component<Props, State> {
<UserContext.Consumer>
{(user) => (
<div className='username'>
<MenuWrapper>
<Button>
{user ? user.username : ' '}
</Button>
<Menu>
<Menu.Text
id='logout'
name={intl.formatMessage({id: 'Sidebar.logout', defaultMessage: 'Log out'})}
onClick={async () => {
octoClient.logout()
window.location.href = '/login'
}}
/>
</Menu>
</MenuWrapper>
</div>
)}
</UserContext.Consumer>

View file

@ -54,6 +54,10 @@ class OctoClient {
return false
}
logout() {
localStorage.removeItem('sessionId')
}
async register(email: string, username: string, password: string, token?: string): Promise<{code: number, json: any}> {
const path = '/api/v1/register'
const body = JSON.stringify({email, username, password, token})