agentleFS
imbhargav5imbhargav5/nextbase-nextjs-supabase-starter/.agents/skills/nextbase-safe-actions-data/SKILL.md

nextbase-safe-actions-data

Skill827 starsChanged 3 months agoMITView on GitHub

Use for NextBase server actions, next-safe-action clients or hooks, forms, Zod validation, authenticated mutations, RLS ownership, data-layer placement, invalidation, redirects, or the optional Effect bridge.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use actionClient from src/lib/safe-action.ts for unauthenticated flows such as sign-in and password recovery.

    line 12
  2. Very specific:

    Use authActionClient for authenticated work.

    line 13
  3. Very specific:

    Keep action modules server-only and place auth actions in src/data/auth, user-scoped actions in src/data/user, and reusable server reads in …

    line 14
  4. Distinctive:

    Check and surface database errors without leaking secrets or internal policy details.

    line 22
  5. Distinctive:

    Keep the form as the smallest possible Client Component.

    line 30
  6. Very specific:

    Use the maintainer hook appropriate to the UX (useAction, optimistic action, or state action) and its status/callback API instead of …

    line 31
  7. Distinctive:

    Use shadcn form controls and accessible labels.

    line 32
  8. Distinctive:

    Test valid input, invalid input, anonymous calls, authenticated ownership, RLS denial, database failure, invalidation, and redirect …

    line 41

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

NextBase Safe Actions and Data

Load the relevant vendored safe-action-* skill for API details and the supabase skill for database behavior.

Action Boundary

  • Use actionClient from src/lib/safe-action.ts for unauthenticated flows such as sign-in and password recovery.
  • Use authActionClient for authenticated work. It supplies ctx.userId; do not accept the owner ID from input.
  • Keep action modules server-only and place auth actions in src/data/auth, user-scoped actions in src/data/user, and reusable server reads in the closest existing data layer.
  • Define a Zod schema at the action boundary. Client form validation improves feedback but does not replace server validation.

Mutation Workflow

  1. Parse and validate with the action schema.
  2. Derive identity and ownership from ctx, never from untrusted input.
  3. Execute through the server Supabase client so cookies and RLS apply.
  4. Check and surface database errors without leaking secrets or internal policy details.
  5. Invalidate the narrow path or cache tag affected by the successful mutation.
  6. Redirect only after the mutation and invalidation succeed.

RLS is the final authorization boundary. An action-level owner filter is defense in depth, not a replacement for an RLS policy.

Client Forms

  • Keep the form as the smallest possible Client Component.
  • Use the maintainer hook appropriate to the UX (useAction, optimistic action, or state action) and its status/callback API instead of duplicating loading and error state.
  • Use shadcn form controls and accessible labels. Preserve progressive enhancement where the flow requires it.
  • Stable field errors come from validation results; unexpected server failures belong in a form-level error.

Effect Bridge

src/utils/effect-bridge.ts and the Effect query helpers are optional adapters for typed effectful code. Reuse them where an adjacent action already uses Effect or where typed error composition materially helps. Do not introduce Effect for a simple one-call mutation.

Verification

Test valid input, invalid input, anonymous calls, authenticated ownership, RLS denial, database failure, invalidation, and redirect behavior at the narrowest suitable layer.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.