tRPCttRPC
Powered by
BarakondaB
tRPC•3y 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;
});
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?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

unstable_pipe/pipe not appearing
Answer OverflowAAnswer Overflow / ❓-help
3y ago
trpc pipe middleware
rustclanRrustclan / ❓-help
3y ago
trpc + unstable_cache (Next)
LedrubLLedrub / ❓-help
2y ago
How to use `localLink` (`unstable_localLink`)
PirulaxPPirulax / ❓-help
6mo ago