BarakondaB
tRPC3y ago
3 replies
Barakonda

async middleware

is it possible to define an async middleware?
I want to do something like this but it throws errors when i start the server

const dbMiddleware = middleware(async ({ path, ctx, next, input }) => {

ctx.path = path;
let session: Pool | null = null;

try {

session = await getSession();
ctx.query = session.query;

let result = await next({ ctx });

if (session)
await session.end();

return result;

} catch (e: any) {
if (session)
await session.end();
}
});
Was this page helpful?