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