> tRPC Middleware & Auth
Add authentication, rate limiting, and error handling middleware to tRPC routers.
fetch
$
curl "https://skillshub.wtf/skillshub-team/catalog-batch5/trpc-middleware?format=md"SKILL.md•tRPC Middleware & Auth
tRPC Middleware
Auth Middleware
const isAuthed = t.middleware(({ ctx, next }) => {
if (!ctx.user) throw new TRPCError({ code: 'UNAUTHORIZED' });
return next({ ctx: { user: ctx.user } });
});
const protectedProcedure = t.procedure.use(isAuthed);
const router = t.router({
getProfile: protectedProcedure.query(({ ctx }) => {
return db.user.findUnique({ where: { id: ctx.user.id } });
}),
});
Rate Limiting
const rateLimited = t.middleware(async ({ ctx, next }) => {
const key = ctx.ip;
const count = await redis.incr(key);
if (count === 1) await redis.expire(key, 60);
if (count > 100) throw new TRPCError({ code: 'TOO_MANY_REQUESTS' });
return next();
});
Error Handling, logging, input validation with Zod
> related_skills --same-repo
> Nix Dev Shells with direnv
Auto-activate reproducible dev environments with Nix flakes and direnv.
> Dagger with GitHub Actions
Run Dagger CI/CD pipelines in GitHub Actions for portable, testable builds.
> Bun + Hono API
Build fast APIs with Bun runtime and Hono framework.
> Deno Fresh Framework
Build full-stack web apps with Fresh on Deno. Islands, routes, and zero runtime overhead.
┌ stats
installs/wk0
░░░░░░░░░░first seenMar 18, 2026
└────────────