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