This commit is contained in:
monoid 2021-01-11 03:42:32 +09:00
parent 8cde19ba25
commit 5996cae0e6
2 changed files with 12 additions and 2 deletions

View File

@ -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}
>
<MenuItem component={RouterLink} to='/profile'>Profile</MenuItem>
<MenuItem>Logout</MenuItem>
<MenuItem onClick={async ()=>{handleProfileMenuClose(); await doLogout(); user_ctx.setUsername("");}}>Logout</MenuItem>
</Menu>);
const drawer_contents = (<>
<div className={classes.toolbar}>

View File

@ -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));
}