This commit is contained in:
Aman Varshney
2025-04-14 21:45:28 +05:30
parent 8b03441909
commit 7f441ef670
268 changed files with 3513 additions and 3039 deletions

View File

@@ -0,0 +1,57 @@
import { createORPCClient } from "@orpc/client";
import { RPCLink } from "@orpc/client/fetch";
import { createORPCReactQueryUtils } from "@orpc/react-query";
import { QueryCache, QueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import type { appRouter } from "../../../server/src/routers/index";
import type { RouterClient } from "@orpc/server";
import { createContext, use } from 'react'
import type { RouterUtils } from '@orpc/react-query'
type ORPCReactUtils = RouterUtils<RouterClient<typeof appRouter>>
export const queryClient = new QueryClient({
queryCache: new QueryCache({
onError: (error) => {
toast.error(`Error: ${error.message}`, {
action: {
label: "retry",
onClick: () => {
queryClient.invalidateQueries();
},
},
});
},
}),
});
export const link = new RPCLink({
{{#if (includes frontend "next")}}
url: `${process.env.NEXT_PUBLIC_SERVER_URL}/rpc`,
{{else}}
url: `${import.meta.env.VITE_SERVER_URL}/rpc`,
{{/if}}
{{#if auth}}
fetch(url, options) {
return fetch(url, {
...options,
credentials: "include",
});
},
{{/if}}
});
export const client: RouterClient<typeof appRouter> = createORPCClient(link)
export const orpc = createORPCReactQueryUtils(client)
export const ORPCContext = createContext<ORPCReactUtils | undefined>(undefined)
export function useORPC(): ORPCReactUtils {
const orpc = use(ORPCContext)
if (!orpc) {
throw new Error('ORPCContext is not set up properly')
}
return orpc
}