Can sign out

This commit is contained in:
Pierre HUBERT 2021-05-12 18:57:30 +02:00
parent e75993b024
commit 1e6de3454f
2 changed files with 20 additions and 1 deletions

View File

@ -89,4 +89,18 @@ export class AccountHelper {
if (currentAccount == null) throw new Error("Current account is null!"); if (currentAccount == null) throw new Error("Current account is null!");
return currentAccount; return currentAccount;
} }
/**
* Sign out current user
*/
static async signOut() {
try {
await serverRequest("accounts/sign_out");
} catch (e) {
console.error(e);
}
sessionStorage.removeItem(SESSION_STORAGE_TOKEN);
document.location.href = document.location.href + "";
}
} }

View File

@ -106,6 +106,11 @@ function Menu() {
export function MainRoute() { export function MainRoute() {
const classes = useStyles(); const classes = useStyles();
const signOut = () => {
AccountHelper.signOut();
};
return ( return (
<Router> <Router>
<AppBar <AppBar
@ -130,7 +135,7 @@ export function MainRoute() {
<small>{AccountHelper.currentAccount.email}</small> <small>{AccountHelper.currentAccount.email}</small>
</Typography> </Typography>
<IconButton aria-label="delete"> <IconButton aria-label="delete" onClick={signOut}>
<CloseSharpIcon /> <CloseSharpIcon />
</IconButton> </IconButton>
</Toolbar> </Toolbar>