\n\n### ๐จโ๐งโ๐ฆ Contributing\n\n- [x] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!",[3034],{"name":3035,"color":3036},"๐ bug: unconfirmed","e99695",6819,"bug: `httpBatchStreamLink` responses use wrong `content-type` header (`application/json`)","2025-06-12T07:54:06Z","https://github.com/trpc/trpc/issues/6819",0.75740594,{"description":3043,"labels":3044,"number":3051,"owner":3025,"repository":3052,"state":3026,"title":3053,"updated_at":3054,"url":3055,"score":3056},"Will unblock https://github.com/jlalmes/trpc-openapi/issues/186",[3045,3048],{"name":3046,"color":3047},"enhancement","a2eeef",{"name":3049,"color":3050},"help wanted","008672",188,"trpc-openapi","Feat: Fetch adapter","2024-03-19T15:10:53Z","https://github.com/trpc/trpc-openapi/issues/188",0.76180565,{"description":3058,"labels":3059,"number":3062,"owner":3025,"repository":3063,"state":3064,"title":3065,"updated_at":3066,"url":3067,"score":3068},"Please discuss\r\n\r\nHow useful is it really? Unexpected errors still needs handling.\r\n\r\n- https://github.com/trpc/v10-playground/pull/17#issuecomment-1019950361\r\n- https://github.com/trpc/v10-playground/pull/17#issuecomment-1020717959",[3060],{"name":3061,"color":3050},"โ RFC",28,"v10-playground","closed","Question: Is it sane to infer errors?","2022-04-11T22:18:27Z","https://github.com/trpc/v10-playground/issues/28",0.7093166,{"description":3070,"labels":3071,"number":3076,"owner":3025,"repository":3025,"state":3064,"title":3077,"updated_at":3078,"url":3079,"score":3080},"- Use `createContext` function to check auth header\r\n- Example: https://github.com/trpc/trpc/blob/a781ed088e72b49702359d4f9368cf2ddabe6130/examples/playground/src/server.ts#L7-L22",[3072,3073],{"name":3019,"color":3020},{"name":3074,"color":3075},"๐ good first issue","7057ff",84,"Doc how you to deal with authentication","2022-10-05T00:10:08Z","https://github.com/trpc/trpc/issues/84",0.7394239,{"description":3082,"labels":3083,"number":3084,"owner":3025,"repository":3025,"state":3064,"title":3085,"updated_at":3086,"url":3087,"score":3088},"### Provide environment information\n\n```\n System:\n OS: macOS 15.3.1\n CPU: (14) arm64 Apple M4 Max\n Memory: 844.22 MB / 36.00 GB\n Shell: 4.0.1 - /usr/local/bin/fish\n Binaries:\n Node: 22.14.0 - ~/.local/state/fnm_multishells/44478_1744539757171/bin/node\n npm: 10.9.2 - ~/.local/state/fnm_multishells/44478_1744539757171/bin/npm\n pnpm: 8.15.5 - ~/.local/state/fnm_multishells/44478_1744539757171/bin/pnpm\n Browsers:\n Brave Browser: 134.1.76.80\n Safari: 18.3\n npmPackages:\n @trpc/server: ^10.45.2 => 10.45.2\n```\n\n### Describe the bug\n\nWhen a validation error happens, the TRPC error returns BAD_REQUEST, but the actual message will be empty.\n\n### Link to reproduction\n\n(currently unable to provide one, will follow up later this week)\n\n### To reproduce\n\n1. Send a request with data that doesn't match the schema\n2. Get back an empty error message\n\n### Additional information\n\nI was able to confirm that this was caused by a validation error by tweaking the input until it matched.\n\nI am using superjson as a transformer, not sure if has as something to do with it.\n\nAlso, it would be great if the fix could be back-ported to v10, as we're currently unable to upgrade to v11 just yet.\n\nI also tried to see what the cause for the error could be, but not sure where in the middleware chain these things get caught just yet.\n\n### ๐จโ๐งโ๐ฆ Contributing\n\n- [ ] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!",[],6718,"bug: Zod v4 beta validation errors return empty message","2025-04-26T18:48:28Z","https://github.com/trpc/trpc/issues/6718",0.7517872,{"description":3090,"labels":3091,"number":3093,"owner":3025,"repository":3025,"state":3064,"title":3094,"updated_at":3095,"url":3096,"score":3097},"### Provide environment information\n\nv10\n\n### Describe the bug\n\nhttps://github.com/trpc/trpc/tree/next/examples/next-prisma-starter-websockets has a type error when using latest version of `next-auth` [as shown here](https://github.com/trpc/examples-next-prisma-starter-websockets)\n\n### To reproduce\n\nSee failing build at https://github.com/trpc/examples-next-prisma-starter-websockets\n\n### Additional information\n\nProbably fixable by upgrading `next-auth` and fixing type error\n\n### ๐จโ๐งโ๐ฆ Contributing\n\n- [X] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!",[3092],{"name":3019,"color":3020},2754,"bug(example): websockets example has type error","2022-10-07T00:12:04Z","https://github.com/trpc/trpc/issues/2754",0.7573527,{"description":3099,"labels":3100,"number":3104,"owner":3025,"repository":3025,"state":3064,"title":3105,"updated_at":3106,"url":3107,"score":3108},"### Provide environment information\r\n```\r\n System:\r\n OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)\r\n CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor\r\n Memory: 25.24 GB / 31.30 GB\r\n Container: Yes\r\n Shell: 5.8 - /usr/bin/zsh\r\n Binaries:\r\n Node: 18.15.0 - ~/.volta/tools/image/node/18.15.0/bin/node\r\n Yarn: 1.22.15 - ~/.volta/bin/yarn\r\n npm: 9.5.0 - ~/.volta/tools/image/node/18.15.0/bin/npm\r\n npmPackages:\r\n @trpc/client: 10.20.0 => 10.20.0 \r\n @trpc/server: 10.20.0 => 10.20.0 \r\n typescript: ^5.0.4 => 5.0.4 \r\n```\r\n\r\n### Describe the bug\r\n\r\nPrior to v10.21.0, we were able to narrow the types of our context in middleware like so:\r\n\r\n```ts\r\n// example context\r\ntype Context =\r\n | { user: null; session: null }\r\n | {\r\n user: {\r\n id: string;\r\n name: string;\r\n };\r\n session: {\r\n id: string;\r\n state: string;\r\n };\r\n};\r\n\r\n// say that we want to add a middleware for logging\r\nconst baseProcedure = t.procedure\r\n .use(async ({ path, type, next }) => {\r\n const start = Date.now();\r\n const result = await next();\r\n const ms = Date.now() - start;\r\n console.log(`${result.ok ? 'OK' : 'ERR'} ${type} ${path} - ${ms}ms`);\r\n return result;\r\n });\r\n\r\nexport const protectedProcedure = baseProcedure.use(({ next, ctx }) => {\r\n // we narrow the type of `user` and `session` by throwing when either are null\r\n if (!ctx.user || !ctx.session) {\r\n throw new TRPCError({ code: 'UNAUTHORIZED', message: 'not signed in' });\r\n }\r\n return next({ ctx });\r\n});\r\n```\r\n\r\nIf we try to add another middleware to this procedure, the type of `ctx.user` still states that it can still be `null`, which is incorrect.\r\n```ts\r\nconst someOtherProcedure = protectedProcedure.use(async ({ next, ctx }) => {\r\n // type of `user` should not be null here as we narrowed its type in the first middleware\r\n ctx.user.id;\r\n // ^? user: { id: string; name: string; } | null\r\n\r\n return next({\r\n ctx: {\r\n ...ctx,\r\n },\r\n });\r\n});\r\n```\r\nIf we comment out the middleware for logging, the type of `ctx.user` would now be correct.\r\n\r\nThe last known version of tRPC that I could find that doesn't exhibit this behavior is v10.20.0.\r\n\r\n### Link to reproduction\r\n\r\nhttps://stackblitz.com/edit/github-yrjz6a?file=src%2Fserver%2Ftrpc.ts%3AL52\r\n\r\n### To reproduce\r\n\r\nUsing tRPC v10.20.0 and below narrows both the `session` and `user` types correctly:\r\nhttps://stackblitz.com/edit/github-yrjz6a-nkddm4?file=src%2Fserver%2Ftrpc.ts%3AL52\r\n\r\nAdditionally, for the reproduction that uses the [latest version of tRPC v10.25.0](https://stackblitz.com/edit/github-yrjz6a?file=src%2Fserver%2Ftrpc.ts%3AL29), if you comment out the logger middleware for the `baseProcedure`, the `ctx` type is corrected. \r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### ๐จโ๐งโ๐ฆ Contributing\r\n\r\n- [ ] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!",[3101],{"name":3102,"color":3103},"๐ bug","d73a4a",4321,"bug: Type narrowing `ctx` in middleware no longer works as of v10.21.0","2023-05-24T00:05:03Z","https://github.com/trpc/trpc/issues/4321",0.7580183,{"description":3110,"labels":3111,"number":3118,"owner":3025,"repository":3025,"state":3064,"title":3119,"updated_at":3120,"url":3121,"score":3122},"### Provide environment information\n\n```\r\n System:\r\n OS: macOS 11.6.8\r\n CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\r\n Memory: 610.94 MB / 32.00 GB\r\n Shell: 5.8 - /bin/zsh\r\n Binaries:\r\n Node: 18.11.0 - ~/.nvm/versions/node/v18.11.0/bin/node\r\n npm: 8.19.2 - ~/.nvm/versions/node/v18.11.0/bin/npm\r\n Browsers:\r\n Brave Browser: 107.1.45.113\r\n Chrome: 106.0.5249.119\r\n Firefox: 105.0.3\r\n Safari: 15.6.1\r\n npmPackages:\r\n @tanstack/react-query: 4.10.0 => 4.10.0 \r\n @trpc/client: 10.0.0-proxy-beta.17 => 10.0.0-proxy-beta.17 \r\n @trpc/next: 10.0.0-proxy-beta.17 => 10.0.0-proxy-beta.17 \r\n @trpc/react: 10.0.0-proxy-beta.17 => 10.0.0-proxy-beta.17 \r\n @trpc/server: 10.0.0-proxy-beta.17 => 10.0.0-proxy-beta.17 \r\n next: 12.3.1 => 12.3.1 \r\n react: 18.2.0 => 18.2.0 \r\n typescript: 4.8.4 => 4.8.4 \r\n```\n\n### Describe the bug\n\nIm trying to utilise NextJs middleware in order to protect all my pages/api routes but I have a problem with `api/trpc` route.\r\nAfter lurking around I found out that the problem lies in httpLink/httpBatchLink due to `fetch` being used by those.\r\nNextjs middleware doing a `redirect` makes that the `api/trpc/...` request will be `text/html` response instead of `application/json` which in turn makes `httpLink/httpBatchLink` throw an error due it expecting an json response.\r\n\r\nFlow: \r\nIncoming request -> NextJs Middleware pick up /api/trpc/.... -> NextJs Middleware redirects /api/trpc request to say /xyz -> `httpLink/httpBatchLink` retrieves request for /api/trpc/.... making a fetch to it -> fetch response here is `text/html` instead of `application/json` and it throws\r\n\r\nSo Could `text/html` response be handled within `httpLink/httpBatchLink` so It would be possible to get back redirect url from such redirected route??\r\n\r\nSomething like ex.\r\nhttps://github.com/trpc/trpc/blob/013c2f281be7eb0e268a59b978509cce7102935f/packages/client/src/links/internals/httpUtils.ts#L141\r\n```\r\n.then((_res) => {\r\n // ----------------------------------------------\r\n const contentType = _res.headers.get(\"content-type\");\r\n\r\n if (contentType === 'text/html' && _res.ok && _res.redirected) {\r\n // either\r\n // throw relevat error type with _res.url so then It can be retreived for making redirect\r\n // handle this somehow for trpc as a valid response and also pass the _res.url so it can be retreived for making redirect\r\n }\r\n\r\n meta.response = _res;\r\n return _res.json();\r\n })\r\n```\r\n\r\n\r\n\n\n### Link to reproduction\n\nhttps://stackblitz.com/edit/github-bbi6vz-nfthcr?file=pages/xyz.tsx\n\n### To reproduce\n\nOpen stackblitz example.\r\nThere is a `middleware` which redirects `trpc/api` requests to `/xyz` page.\r\nIn the console you would see `TRPCClientError: Unexpected token '\u003C', \"\u003C!DOCTYPE \"... is not valid JSON` because redirect makes the `trpc/api` response as `text/html` not `application/json`\r\n\r\n\n\n### Additional information\n\nSimply put, the browser won't do document follow on a redirect originated from a `fetch` request. \r\n\r\nSo I would expect to be able to somehow retrieve the redirect url from within the `httpLink/httpBatchLink` because thats the one responsible to making that fetch call.\n\n### ๐จโ๐งโ๐ฆ Contributing\n\n- [ ] ๐โโ๏ธ Yes, I'd be down to file a PR fixing this bug!",[3112,3115],{"name":3113,"color":3114},"@trpc/client","6095C2",{"name":3116,"color":3117},"๐ needs more investigation/info","d4c5f9",3081,"httpLink/httpBatchLink on fetch redirect","2022-12-11T18:01:41Z","https://github.com/trpc/trpc/issues/3081",0.75805813,{"description":3124,"labels":3125,"number":3130,"owner":3025,"repository":3025,"state":3064,"title":3131,"updated_at":3132,"url":3133,"score":3134},"### Discussed in https://github.com/trpc/trpc/discussions/6171\r\n\r\n\r\n\r\n\u003Csup>Originally posted by **morleytatro** October 31, 2024\u003C/sup>\r\n> \r\n> I'm looking to do the following:\r\n> https://stackoverflow.com/questions/77096846/wrap-usequery-of-trpc-in-a-custom-hook-with-correct-typescript-types\r\n> \r\n> The solution mentioned works for v10 but the typing completely falls apart for v11. Looks like there's substantial interest from the community:\r\n> https://discord.com/channels/867764511159091230/1020132255567454310/threads/1151511450859356170\r\n> \r\n> Has anyone made any headway on this or have any suggestions.",[3126,3127],{"name":3019,"color":3020},{"name":3128,"color":3129},"๐ฐ wontfix/$$$$","ffffff",6180,"How to create a custom hook with inferred return types","2025-03-20T15:42:40Z","https://github.com/trpc/trpc/issues/6180",0.76151913,["Reactive",3136],{},["Set"],["ShallowReactive",3139],{"$fTRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"$fpkzgQHgSLSSl1kizU8CZY62POnZl3FM4QPN5FgNwqd8":-1},"/trpc/v10-playground/1"]