mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 12:11:51 +02:00
♻️ Move trpc client code to app (#906)
This commit is contained in:
parent
502f2a7a43
commit
5be17fd249
34 changed files with 133 additions and 124 deletions
|
@ -1,40 +0,0 @@
|
|||
import { MutationCache } from "@tanstack/react-query";
|
||||
import { httpBatchLink } from "@trpc/client";
|
||||
import { createTRPCNext } from "@trpc/next";
|
||||
import toast from "react-hot-toast";
|
||||
import superjson from "superjson";
|
||||
|
||||
import { AppRouter } from "../../trpc/routers";
|
||||
|
||||
export * from "../../trpc/types";
|
||||
|
||||
export const trpc = createTRPCNext<AppRouter>({
|
||||
config() {
|
||||
return {
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: `/api/trpc`,
|
||||
}),
|
||||
],
|
||||
transformer: superjson,
|
||||
queryClientConfig: {
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
networkMode: "always",
|
||||
cacheTime: Infinity,
|
||||
staleTime: 1000 * 60,
|
||||
},
|
||||
},
|
||||
mutationCache: new MutationCache({
|
||||
onError: () => {
|
||||
toast.error(
|
||||
"Uh oh! Something went wrong. The issue has been logged and we'll fix it as soon as possible. Please try again later.",
|
||||
);
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
},
|
||||
ssr: false,
|
||||
});
|
|
@ -1,27 +0,0 @@
|
|||
import { EmailClient } from "@rallly/emails";
|
||||
import * as trpcNext from "@trpc/server/adapters/next";
|
||||
|
||||
import { appRouter } from "../../trpc/routers";
|
||||
|
||||
export interface TRPCContext {
|
||||
user: { id: string; isGuest: boolean };
|
||||
emailClient: EmailClient;
|
||||
isSelfHosted: boolean;
|
||||
isEmailBlocked?: (email: string) => boolean;
|
||||
/**
|
||||
* Takes a relative path and returns an absolute URL to the app
|
||||
* @param path
|
||||
* @returns absolute URL
|
||||
*/
|
||||
absoluteUrl: (path?: string) => string;
|
||||
shortUrl: (path?: string) => string;
|
||||
}
|
||||
|
||||
export const trpcNextApiHandler = (context: TRPCContext) => {
|
||||
return trpcNext.createNextApiHandler({
|
||||
router: appRouter,
|
||||
createContext: async () => {
|
||||
return context;
|
||||
},
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue