From 28c3a8395b98f673669f1db37290bd9688167287 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 23 Jan 2020 18:41:11 +0200 Subject: [PATCH] Logout: invalidate the auth token after logging out. --- src/SideMenu/index.tsx | 2 +- src/store/actions.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/SideMenu/index.tsx b/src/SideMenu/index.tsx index b317e2c..8be80a0 100644 --- a/src/SideMenu/index.tsx +++ b/src/SideMenu/index.tsx @@ -39,7 +39,7 @@ class SideMenu extends React.PureComponent { } public logout() { - store.dispatch(logout()); + store.dispatch(logout(this.props.etesync!)); this.props.onCloseDrawerRequest(); } diff --git a/src/store/actions.ts b/src/store/actions.ts index 095b217..1d05ffe 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -5,7 +5,7 @@ import { UserInfo } from 'etesync'; import { CredentialsData, EntriesType, SettingsType } from './'; -export const { fetchCredentials, logout } = createActions({ +export const { fetchCredentials } = createActions({ FETCH_CREDENTIALS: (username: string, password: string, server: string) => { const authenticator = new EteSync.Authenticator(server); @@ -27,9 +27,23 @@ export const { fetchCredentials, logout } = createActions({ ); }); }, - LOGOUT: () => undefined, }); +export const logout = createAction( + 'LOGOUT', + (etesync: CredentialsData) => { + (async () => { + const authenticator = new EteSync.Authenticator(etesync.serviceApiUrl); + try { + await authenticator.invalidateToken(etesync.credentials.authToken); + } catch { + // Ignore for now. It usually means the token was a legacy one. + } + })(); + return; // We are not waiting on the above on purpose for now, just invalidate the token in the background + } +); + export const { deriveKey } = createActions({ DERIVE_KEY: (username: string, encryptionPassword: string) => { return EteSync.deriveKey(username, encryptionPassword);