BarakondaB
tRPC3y ago
3 replies
Barakonda

pipe/unstable_pipe

I cant seem to find it? according to the docs I can chain middlewares using pipe in v10 but the feature isn't there
this is a simple example from the docs

const t =  initTRPC.context<Context>().create();

export const middleware = t.middleware;
export const router = t.router;

const checkTokenMW = middleware(async ({ctx, next}) => {
    if(!ctx.req.headers.authorization){
        throw new TRPCError({code: 'UNAUTHORIZED'});
    }

    ctx.userData.userId = 3;

    return next({ctx});
});

const loggerMW = middleware(async ({path, next}) => {
    const start = Date.now();
    const result = await next();
    const durationMs = Date.now() - start;
    result.ok
      ? console.log('OK request %s duration: %d', { path, durationMs })
      : console.log('Non-OK request %s duration: %d', { path, durationMs });
   
    return result;
});


I want to do something like this checkTokenMW.unstable_pipe(loggerMW) - or like in the example entering the middleware code directly
but there is no method to do this, am i doing something wrong or maybe how to do this changed and the docs aren't updated?
can you please help me figure this out?
Was this page helpful?