From 5996cae0e651d6913000ab148d6ba6253fda8f56 Mon Sep 17 00:00:00 2001 From: monoid Date: Mon, 11 Jan 2021 03:42:32 +0900 Subject: [PATCH] logout --- src/client/component/headline.tsx | 4 ++-- src/client/state.tsx | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/client/component/headline.tsx b/src/client/component/headline.tsx index d5e8f5d..ab16f67 100644 --- a/src/client/component/headline.tsx +++ b/src/client/component/headline.tsx @@ -8,7 +8,7 @@ import { import { makeStyles, Theme, useTheme, fade } from '@material-ui/core/styles'; import { ChevronLeft, ChevronRight, Menu as MenuIcon, Search as SearchIcon, AccountCircle } from '@material-ui/icons'; import { Link as RouterLink, useRouteMatch } from 'react-router-dom'; -import { UserContext } from '../state'; +import { doLogout, UserContext } from '../state'; const drawerWidth = 240; @@ -135,7 +135,7 @@ export const Headline = (prop: { onClose={handleProfileMenuClose} > Profile - Logout + {handleProfileMenuClose(); await doLogout(); user_ctx.setUsername("");}}>Logout ); const drawer_contents = (<>
diff --git a/src/client/state.tsx b/src/client/state.tsx index 799c824..5a1fd97 100644 --- a/src/client/state.tsx +++ b/src/client/state.tsx @@ -44,4 +44,14 @@ export const getInitialValue = async () => { username: r.username, permission: r.permission } +} +export const doLogout = async ()=>{ + const res = await fetch('/user/logout', { + method: 'POST', + }); + await res.json(); + localObj.refreshExpired = 0; + localObj.username = ""; + localObj.permission = []; + window.localStorage.setItem("UserLoginContext", JSON.stringify(localObj)); } \ No newline at end of file