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/mobile/lib/providers.tsx | 51 +++++--------------------------------------
 1 file changed, 5 insertions(+), 46 deletions(-)

(limited to 'apps/mobile/lib/providers.tsx')

diff --git a/apps/mobile/lib/providers.tsx b/apps/mobile/lib/providers.tsx
index ed04b9bf..c2a573f5 100644
--- a/apps/mobile/lib/providers.tsx
+++ b/apps/mobile/lib/providers.tsx
@@ -1,52 +1,11 @@
-import { useEffect, useMemo } from "react";
+import { useEffect } from "react";
 import { SafeAreaProvider } from "react-native-safe-area-context";
 import FullPageSpinner from "@/components/ui/FullPageSpinner";
 import { ToastProvider } from "@/components/ui/Toast";
-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { httpBatchLink } from "@trpc/client";
-import superjson from "superjson";
 
-import type { Settings } from "./settings";
-import useAppSettings from "./settings";
-import { api } from "./trpc";
-
-function getTRPCClient(settings: Settings) {
-  return api.createClient({
-    links: [
-      httpBatchLink({
-        url: `${settings.address}/api/trpc`,
-        headers() {
-          return {
-            Authorization: settings?.apiKey
-              ? `Bearer ${settings.apiKey}`
-              : undefined,
-          };
-        },
-        transformer: superjson,
-      }),
-    ],
-  });
-}
-
-function TrpcProvider({
-  children,
-  settings,
-}: {
-  settings: Settings;
-  children: React.ReactNode;
-}) {
-  const queryClient = useMemo(() => new QueryClient(), [settings]);
-
-  const trpcClient = useMemo(() => getTRPCClient(settings), [settings]);
+import { TRPCProvider } from "@hoarder/shared-react/providers/trpc-provider";
 
-  return (
-    <api.Provider client={trpcClient} queryClient={queryClient}>
-      <QueryClientProvider client={queryClient}>
-        <ToastProvider>{children}</ToastProvider>
-      </QueryClientProvider>
-    </api.Provider>
-  );
-}
+import useAppSettings from "./settings";
 
 export function Providers({ children }: { children: React.ReactNode }) {
   const { settings, isLoading, load } = useAppSettings();
@@ -62,9 +21,9 @@ export function Providers({ children }: { children: React.ReactNode }) {
 
   return (
     <SafeAreaProvider>
-      <TrpcProvider settings={settings}>
+      <TRPCProvider settings={settings}>
         <ToastProvider>{children}</ToastProvider>
-      </TrpcProvider>
+      </TRPCProvider>
     </SafeAreaProvider>
   );
 }
-- 
cgit v1.2.3-70-g09d2

