diff options
Diffstat (limited to 'apps/mobile/lib')
| -rw-r--r-- | apps/mobile/lib/providers.tsx | 51 | ||||
| -rw-r--r-- | apps/mobile/lib/session.ts | 8 | ||||
| -rw-r--r-- | apps/mobile/lib/settings.ts | 1 |
3 files changed, 13 insertions, 47 deletions
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> ); } diff --git a/apps/mobile/lib/session.ts b/apps/mobile/lib/session.ts index bafb3a09..8eb646cb 100644 --- a/apps/mobile/lib/session.ts +++ b/apps/mobile/lib/session.ts @@ -1,12 +1,18 @@ import { useCallback } from "react"; import useAppSettings from "./settings"; +import { api } from "./trpc"; export function useSession() { const { settings, setSettings } = useAppSettings(); + const { mutate: deleteKey } = api.apiKeys.revoke.useMutation(); + const logout = useCallback(() => { - setSettings({ ...settings, apiKey: undefined }); + if (settings.apiKeyId) { + deleteKey({ id: settings.apiKeyId }); + } + setSettings({ ...settings, apiKey: undefined, apiKeyId: undefined }); }, [settings, setSettings]); return { diff --git a/apps/mobile/lib/settings.ts b/apps/mobile/lib/settings.ts index 3ec53231..efb5593a 100644 --- a/apps/mobile/lib/settings.ts +++ b/apps/mobile/lib/settings.ts @@ -5,6 +5,7 @@ const SETTING_NAME = "settings"; export interface Settings { apiKey?: string; + apiKeyId?: string; address: string; } |
