warflash
warflash8mo ago

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 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!
0 Replies
No replies yetBe the first to reply to this messageJoin