
t variable from your main trpc file, and then create the middleware// https://trpc.io/docs/v10/middlewares#authorization
const isAdmin = t.middleware(async ({ ctx, next }) => {
if (!ctx.user?.isAdmin) {
throw new TRPCError({ code: 'UNAUTHORIZED' });
}
return next({
ctx: {
user: ctx.user,
}
});
});
const adminProcedure = t.procedure.use(isAdmin);export const t = initTRPC.context<Context>().create();import {t} from "./trpc";