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/utils/providers.tsx | 44 ++------------------------
 1 file changed, 3 insertions(+), 41 deletions(-)

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

diff --git a/apps/browser-extension/src/utils/providers.tsx b/apps/browser-extension/src/utils/providers.tsx
index 7b14b22c..4ca17016 100644
--- a/apps/browser-extension/src/utils/providers.tsx
+++ b/apps/browser-extension/src/utils/providers.tsx
@@ -1,47 +1,9 @@
-import { useEffect, useState } from "react";
-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { httpBatchLink } from "@trpc/client";
-import superjson from "superjson";
+import { TRPCProvider } from "@hoarder/shared-react/providers/trpc-provider";
 
-import usePluginSettings, { getPluginSettings } from "./settings";
-import { api } from "./trpc";
-
-function getTRPCClient(address: string) {
-  return api.createClient({
-    links: [
-      httpBatchLink({
-        url: `${address}/api/trpc`,
-        async headers() {
-          const settings = await getPluginSettings();
-          return {
-            Authorization: `Bearer ${settings.apiKey}`,
-          };
-        },
-        transformer: superjson,
-      }),
-    ],
-  });
-}
+import usePluginSettings from "./settings";
 
 export function Providers({ children }: { children: React.ReactNode }) {
   const { settings } = usePluginSettings();
-  const [queryClient] = useState(() => new QueryClient());
-
-  const [trpcClient, setTrpcClient] = useState<
-    ReturnType<typeof getTRPCClient>
-  >(getTRPCClient(settings.address));
-
-  useEffect(() => {
-    setTrpcClient(getTRPCClient(settings.address));
-  }, [settings.address]);
 
-  return (
-    <api.Provider
-      key={settings.address}
-      client={trpcClient}
-      queryClient={queryClient}
-    >
-      <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
-    </api.Provider>
-  );
+  return <TRPCProvider settings={settings}>{children}</TRPCProvider>;
 }
-- 
cgit v1.2.3-70-g09d2

