From adb7a765b424a2c23a7fe916fd969863853c4503 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Mon, 16 Jan 2023 22:22:19 +0100 Subject: [PATCH] Fix #663 Properly revoke token when actively logging out --- src/screens/Tabs/Me/Root/Logout.tsx | 2 +- src/utils/storage/actions.ts | 36 +++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/screens/Tabs/Me/Root/Logout.tsx b/src/screens/Tabs/Me/Root/Logout.tsx index fc11cdc8..25375653 100644 --- a/src/screens/Tabs/Me/Root/Logout.tsx +++ b/src/screens/Tabs/Me/Root/Logout.tsx @@ -32,7 +32,7 @@ const Logout: React.FC = () => { onPress: () => { if (accountActive) { haptics('Light') - removeAccount(accountActive) + removeAccount(accountActive, false) } } }, diff --git a/src/utils/storage/actions.ts b/src/utils/storage/actions.ts index d0383e1f..d25dd945 100644 --- a/src/utils/storage/actions.ts +++ b/src/utils/storage/actions.ts @@ -264,14 +264,40 @@ export const setAccount = async (account: string) => { }) } -export const removeAccount = async (account: string) => { - displayMessage({ - message: i18n.t('screens:localCorrupt.message'), - type: 'danger' - }) +export const removeAccount = async (account: string, warning: boolean = true) => { + const temp = new MMKV({ id: account }) + + if (warning) { + const acct = temp.getString('auth.account.acct') + const domain = temp.getString('auth.account.domain') + displayMessage({ + message: i18n.t('screens:localCorrupt.message'), + ...(acct && domain && { description: `@${acct}@${domain}` }), + type: 'danger' + }) + } // @ts-ignore navigationRef.navigate('Screen-Tabs', { screen: 'Tab-Me' }) + const revokeDetails = { + domain: temp.getString('auth.domain'), + client_id: temp.getString('auth.clientId'), + client_secret: temp.getString('auth.clientSecret'), + token: temp.getString('auth.token') + } + if ( + revokeDetails.domain && + revokeDetails.client_id && + revokeDetails.client_secret && + revokeDetails.token + ) { + const body = new FormData() + body.append('client_id', revokeDetails.client_id) + body.append('client_secret', revokeDetails.client_secret) + body.append('token', revokeDetails.token) + apiGeneral({ method: 'post', domain: revokeDetails.domain, url: '/oauth/revoke', body }) + } + const currAccounts: NonNullable = getGlobalStorage.object('accounts') || [] const nextAccounts: NonNullable = currAccounts.filter(