forinda/euc-app/guard-vs-middleware-vs-contributor

Claude Code and agent skill by forinda/euc-app

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when adding auth checks, request-scoped values, or anything "before the handler" — picks between a guard, a middleware, and a context contributor.

Install

npx vskill@latest install forinda/euc-app/guard-vs-middleware-vs-contributor

SKILL.md

The same SKILL.md was published earlier as forinda/euc-app/guard-vs-middleware-vs-contributor.

KickJS has no guard primitive. There is no @Guard, no canActivate, no guard class to implement. A guard IS a middleware — the word only names a convention and a directory. If you are porting NestJS habits, this is the first thing to unlearn.

GuardMiddlewareContext contributor
What it isa middleware, by conventiona middlewarea declarative value producer
Signature(ctx, next)(ctx, next) on @Middleware(), (req, res, next) in bootstrap({ middlewares })resolve(ctx, deps) returning a value
Can end the requestyesyesno
Runsin the middleware stagein the middleware stageafter ALL middleware
Attached by@Middleware(fn)@Middleware(fn) or bootstrap({ middlewares })@LoadX, or a registration at module / adapter / bootstrap level
Generatorkick g guard <name>kick g middleware <name>kick g contributor <name>
Lands insrc/guards/<name>.guard.tssrc/middleware/<name>.middleware.tssrc/contributors/<name>.contributor.ts

Add -m <module> to any of those generators to place the file inside a module instead of the app-level directory.

Choosing: does the thing ever need to STOP the request?

  • Yes, and it is authorization → guard.
  • Yes, anything else (rate limit, body rewrite, response stream, work before route matching) → middleware.
  • No, it only computes a value the handler or a service reads off ctx → contributor. Typed, ordered, boot-validated, and it cannot silently swallow the request.

Ordering — guards run BEFORE contributors. Every runtime does the same thing: run entry.middlewares in order, bail if the response was written, then run the contributor pipeline, then the handler. So:

ts
// WRONG — tenant is always undefined here.
export async function tenantGuard(ctx: RequestContext, next: () => void) {
const tenant = ctx.get('tenant') // contributors have not run yet
if (!tenant) return ctx.problem.forbidden()
next()
}

A guard that needs a resolved value must resolve it itself, or the check belongs in the contributor's own resolve (throw from there and the request error handler takes over).

Write responses with `ctx.*`, never `ctx.res`. ctx.res is the ENGINE-NATIVE response object, so ctx.res.status(401).json(...) only works on Express — FastifyReply has no .json() and h3's event has no .status(). Use ctx.problem.unauthorized({ detail }) (RFC 9457) or ctx.json(body, status), and the helper for anything else you would reach ctx.res for: ctx.download(buffer, filename, contentType?) for a generated file, ctx.html(content), ctx.redirect(url, status?), ctx.sse() for a stream. All of them work on all four runtimes. Never hand ctx.redirect a destination taken from the request unchecked — allow-list it, or accept only a same-site path (one leading /, not //) — or the route is an open redirect.

Guard shape:

ts
import type { RequestContext } from '@forinda/kickjs'
export async function adminGuard(ctx: RequestContext, next: () => void): Promise<void> {
const user = ctx.session?.user // requires the session middleware
if (!user) {
ctx.problem.unauthorized({ detail: 'Not signed in' })
return // do NOT call next()
}
if (user.role !== 'admin') {
ctx.problem.forbidden({ detail: 'Admin only' })
return
}
next()
}
ts
@Middleware(adminGuard)
@Get('/admin/stats')
stats(ctx: RequestContext) { ... }

Role checks that are purely declarative (@Public(), @Roles('admin'), @Can(...)) are yours to define — see the BYO Auth recipe in the docs. Hand-write a guard only for logic those don't express.

Red flags:

  • class AdminGuard implements CanActivate / @UseGuards() — NestJS, not KickJS. Export a (ctx, next) function and attach with @Middleware().
  • A guard calling next() AND writing a response — pick one; writing then continuing double-sends.
  • A guard reading ctx.get(...) for a contributor-produced key — contributors have not run yet.
  • ctx.res.status(403).json(...) in a guard — Express-only. Use ctx.problem.forbidden().
  • A "guard" that only sets a value and always calls next() — that is a contributor wearing a guard's name.
  • Passing a (ctx, next) guard to bootstrap({ middlewares }) — global middleware is connect-style (req, res, next). Mount guards per-route with @Middleware().

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/forinda/euc-app/guard-vs-middleware-vs-contributor/badge)](https://verified-skill.com/skills/forinda/euc-app/guard-vs-middleware-vs-contributor)

Something wrong with this skill or its page? Tell us.