feat: add trpc logger
This commit is contained in:
parent
3bd7266dcf
commit
6723b9f3da
@ -1,9 +1,10 @@
|
|||||||
import { createTRPCReact } from '@trpc/react-query';
|
import { createTRPCReact } from '@trpc/react-query';
|
||||||
import type { AppRouter } from '../../server/trpc/routers';
|
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 { getJWT } from './auth';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
import type { inferRouterInputs, inferRouterOutputs } from '@trpc/server';
|
||||||
|
import { isDev } from '../utils/env';
|
||||||
|
|
||||||
export const trpc = createTRPCReact<AppRouter>();
|
export const trpc = createTRPCReact<AppRouter>();
|
||||||
|
|
||||||
@ -12,6 +13,11 @@ export type RouterOutput = inferRouterOutputs<AppRouter>;
|
|||||||
|
|
||||||
export const trpcClient = trpc.createClient({
|
export const trpcClient = trpc.createClient({
|
||||||
links: [
|
links: [
|
||||||
|
loggerLink({
|
||||||
|
enabled: (opts) =>
|
||||||
|
(isDev && typeof window !== 'undefined') ||
|
||||||
|
(opts.direction === 'down' && opts.result instanceof Error),
|
||||||
|
}),
|
||||||
httpBatchLink({
|
httpBatchLink({
|
||||||
url: '/trpc',
|
url: '/trpc',
|
||||||
async headers() {
|
async headers() {
|
||||||
|
1
src/client/utils/env.ts
Normal file
1
src/client/utils/env.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const isDev = import.meta.env.MODE === 'development';
|
Loading…
x
Reference in New Issue
Block a user