-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Delete the API key on logout from phone or extension
- Loading branch information
1 parent
5ab6c33
commit f696d33
Showing
11 changed files
with
84 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useMemo } from "react"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { httpBatchLink } from "@trpc/client"; | ||
import superjson from "superjson"; | ||
|
||
import { api } from "../trpc"; | ||
|
||
interface Settings { | ||
apiKey?: string; | ||
address: string; | ||
} | ||
|
||
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, | ||
}), | ||
], | ||
}); | ||
} | ||
|
||
export function TRPCProvider({ | ||
settings, | ||
children, | ||
}: { | ||
settings: Settings; | ||
children: React.ReactNode; | ||
}) { | ||
const queryClient = useMemo(() => new QueryClient(), [settings]); | ||
const trpcClient = useMemo(() => getTRPCClient(settings), [settings]); | ||
|
||
return ( | ||
<api.Provider | ||
key={settings.address} | ||
client={trpcClient} | ||
queryClient={queryClient} | ||
> | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
</api.Provider> | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.