summaryrefslogtreecommitdiffstats
path: root/frontend/src/LogoutBtn.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/LogoutBtn.js')
-rw-r--r--frontend/src/LogoutBtn.js22
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} />;