diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2020-01-31 19:20:13 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2020-01-31 19:20:13 +0200 |
| commit | fbf108595a00a7c9db5984158e4b02cc345b68d1 (patch) | |
| tree | f3342eac03006d40a23a49fac94db7061abf5d3c /frontend/src/LogoutBtn.js | |
Initial commit
Diffstat (limited to 'frontend/src/LogoutBtn.js')
| -rw-r--r-- | frontend/src/LogoutBtn.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/frontend/src/LogoutBtn.js b/frontend/src/LogoutBtn.js new file mode 100644 index 0000000..f8b1827 --- /dev/null +++ b/frontend/src/LogoutBtn.js @@ -0,0 +1,22 @@ +import React from 'react'; +import { navigate } from '@reach/router'; +import { observer } from 'mobx-react'; + +import axios from './axios'; +import userState from './UserState'; + +const LogoutBtn = observer(({ user }) => { + const doLogout = async () => { + await axios.post('/logout'); + user.username = null; + navigate('/login'); + }; + + return ( + <button onClick={doLogout} type="button"> + Log out + </button> + ); +}); + +export default () => <LogoutBtn user={userState} />; |
