forinda/euc-app/guard-vs-middleware-vs-contributor
Claude Code and agent skill by forinda/euc-app
- community
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-contributorSKILL.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.
| Guard | Middleware | Context contributor | ||
|---|---|---|---|---|
| What it is | a middleware, by convention | a middleware | a 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 request | yes | yes | no | |
| Runs | in the middleware stage | in the middleware stage | after ALL middleware | |
| Attached by | @Middleware(fn) | @Middleware(fn) or bootstrap({ middlewares }) | @LoadX, or a registration at module / adapter / bootstrap level | |
| Generator | kick g guard <name> | kick g middleware <name> | kick g contributor <name> | |
| Lands in | src/guards/<name>.guard.ts | src/middleware/<name>.middleware.ts | src/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:
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:
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. Usectx.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 tobootstrap({ 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
- SKILL.md in the repositoryCheckingserver/.agents/skills/guard-vs-middleware-vs-contributor/SKILL.md
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
[](https://verified-skill.com/skills/forinda/euc-app/guard-vs-middleware-vs-contributor)