tRPCttRPC
Powered by
warflashW
tRPC•2y ago•
1 reply
warflash

Middleware context changes aren't applied to `responseMeta(opts)` options

In our middleware I extend the ctx like this:
const public = t.middleware(async ({ next, ctx }) => {
    return next({
        ctx: {
            enableCache: true,
        },
    })
})
const public = t.middleware(async ({ next, ctx }) => {
    return next({
        ctx: {
            enableCache: true,
        },
    })
})

and then in the api handler where I'd like to add cache headers in the
reponseMeta
reponseMeta
function I try accessing ctx. However it hasn't been modified there and returns an empty object. Accessing ctx in my router procedure itself properly returns the right context.
export default trpcNext.createNextApiHandler({
  router: appRouter,
  createContext,
  responseMeta(opts) {
    console.log(opts);
    return {};
  },
});
export default trpcNext.createNextApiHandler({
  router: appRouter,
  createContext,
  responseMeta(opts) {
    console.log(opts);
    return {};
  },
});


Any idea on how I can get this to work? Thank you!
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Request context inside middleware?
HuzefHHuzef / ❓-help
4y ago
[v11] Change responseMeta in procedure
SongkeysSSongkeys / ❓-help
2y ago
Creating inner context for AWS Lambda Context Options
NicolasNNicolas / ❓-help
3y ago