From f696d33b645c53369ec5833593bdc77c9fb7cea9 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Tue, 9 Apr 2024 19:05:28 +0100
Subject: fix: Delete the API key on logout from phone or extension

---
 apps/browser-extension/src/OptionsPage.tsx | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'apps/browser-extension/src/OptionsPage.tsx')

diff --git a/apps/browser-extension/src/OptionsPage.tsx b/apps/browser-extension/src/OptionsPage.tsx
index 9670558e..24785857 100644
--- a/apps/browser-extension/src/OptionsPage.tsx
+++ b/apps/browser-extension/src/OptionsPage.tsx
@@ -17,6 +17,8 @@ export default function OptionsPage() {
     },
   );
 
+  const { mutate: deleteKey } = api.apiKeys.revoke.useMutation();
+
   const invalidateWhoami = api.useUtils().users.whoami.refetch;
 
   useEffect(() => {
@@ -39,7 +41,10 @@ export default function OptionsPage() {
   }
 
   const onLogout = () => {
-    setSettings((s) => ({ ...s, apiKey: "" }));
+    if (settings.apiKeyId) {
+      deleteKey({ id: settings.apiKeyId });
+    }
+    setSettings((s) => ({ ...s, apiKey: "", apiKeyId: undefined }));
     invalidateWhoami();
     navigate("/notconfigured");
   };
-- 
cgit v1.2.3-70-g09d2

