diff --git a/src/client/api/trpc.ts b/src/client/api/trpc.ts index a84242b..8a33482 100644 --- a/src/client/api/trpc.ts +++ b/src/client/api/trpc.ts @@ -1,9 +1,10 @@ import { createTRPCReact } from '@trpc/react-query'; import type { AppRouter } from '../../server/trpc/routers'; -import { httpBatchLink, TRPCClientErrorLike } from '@trpc/client'; +import { httpBatchLink, loggerLink, TRPCClientErrorLike } from '@trpc/client'; import { getJWT } from './auth'; import { message } from 'antd'; import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server'; +import { isDev } from '../utils/env'; export const trpc = createTRPCReact(); @@ -12,6 +13,11 @@ export type RouterOutput = inferRouterOutputs; export const trpcClient = trpc.createClient({ links: [ + loggerLink({ + enabled: (opts) => + (isDev && typeof window !== 'undefined') || + (opts.direction === 'down' && opts.result instanceof Error), + }), httpBatchLink({ url: '/trpc', async headers() { diff --git a/src/client/utils/env.ts b/src/client/utils/env.ts new file mode 100644 index 0000000..962a821 --- /dev/null +++ b/src/client/utils/env.ts @@ -0,0 +1 @@ +export const isDev = import.meta.env.MODE === 'development';