From 1e6de3454f19519f94c5423dd2900e5637e5dc59 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 12 May 2021 18:57:30 +0200 Subject: [PATCH] Can sign out --- src/helpers/AccountHelper.ts | 14 ++++++++++++++ src/ui/routes/MainRoute.tsx | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/helpers/AccountHelper.ts b/src/helpers/AccountHelper.ts index 152f8a9..7e839e4 100644 --- a/src/helpers/AccountHelper.ts +++ b/src/helpers/AccountHelper.ts @@ -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 + ""; + } } diff --git a/src/ui/routes/MainRoute.tsx b/src/ui/routes/MainRoute.tsx index 4cc67eb..0d93c4f 100644 --- a/src/ui/routes/MainRoute.tsx +++ b/src/ui/routes/MainRoute.tsx @@ -106,6 +106,11 @@ function Menu() { export function MainRoute() { const classes = useStyles(); + + const signOut = () => { + AccountHelper.signOut(); + }; + return ( {AccountHelper.currentAccount.email} - +