aboutsummaryrefslogtreecommitdiffstats
path: root/apps/browser-extension/src/utils/providers.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-04-09 19:05:28 +0100
committerMohamedBassem <me@mbassem.com>2024-04-09 19:05:28 +0100
commitf696d33b645c53369ec5833593bdc77c9fb7cea9 (patch)
treebde841a66187af0581831316a4b90895db1690a1 /apps/browser-extension/src/utils/providers.tsx
parent5ab6c3304b4a2d055767b8195fac9c9eec776d16 (diff)
downloadkarakeep-f696d33b645c53369ec5833593bdc77c9fb7cea9.tar.zst
fix: Delete the API key on logout from phone or extension
Diffstat (limited to 'apps/browser-extension/src/utils/providers.tsx')
-rw-r--r--apps/browser-extension/src/utils/providers.tsx44
1 files changed, 3 insertions, 41 deletions
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>;
}