/factory-kit:factory-auth-wiring-specialistfrom factory-kit
Wires auth into new projects or switches providers using a decision matrix (Better Auth + orgs, Supabase + RLS, Clerk). Creates unified requireAuth/requireRole/withOrgContext wrappers, enforces multi-tenancy, handles OAuth safety, JWT verification, and admin-client guardrails.
Ships in factory-kit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Apply the auth-wiring-specialist workflow. Wire auth using the factory's conventions, not generic provider-specific boilerplate. Load the canonical factory-auth and factory-security skills through the host's skill capability when needed.
Which provider? Apply the decision matrix:
If the user has expressed a preference or the project already has a provider, defer to that. Otherwise pick from the matrix and flag.
Wrapper interface present? Check for src/lib/auth/ (or equivalent). The seam is:
requireAuth() -> { user, session }requireRole(role) -> { user, session }withOrgContext(fn) — wraps an async function with org contextIf the seam exists, use it. If not, create it before writing any new auth-touching code.
Procedure tiers? For tRPC projects:
publicProcedure — anyoneprotectedProcedure = publicProcedure.use(requireAuth)orgProcedure = protectedProcedure.use(requireOrg)For server-action projects, the equivalent is calling the wrappers at the top of each action.
Multi-tenancy enforcement? Every domain query / mutation must:
orgId from session via withOrgContextorgId in the query / mutationorgId from the request body — always from the sessionOAuth flows?
?next= params with safeNext() — reject protocol-relative, non-relative URLs/admin, rep → /submit, default /)?next= for OAuth callback flows (too easy to weaponize on first sign-in)JWT verification? (Clerk / Supabase)
Admin / service-role client?
withAdmin(fn) — never expose at module scoperequireAdmin() inside the wrapper before returning the clientfactory-security.mdRole definition? Don't put roles in code as string literals. Define an enum / const and reference it:
export const ROLES = ['owner', 'admin', 'member', 'guest'] as const;
export type Role = (typeof ROLES)[number];
// src/lib/auth/index.ts
import { auth } from './provider'; // Better Auth / Supabase / Clerk import
export class AuthError extends Error {
constructor(public reason: 'unauthenticated' | 'forbidden' | 'no_org_context') {
super(reason);
}
}
export async function requireAuth() {
const session = await auth.getSession();
if (!session) throw new AuthError('unauthenticated');
return { user: session.user, session };
}
export async function requireRole(role: Role) {
const ctx = await requireAuth();
if (!ctx.user.roles.includes(role)) throw new AuthError('forbidden');
return ctx;
}
export async function withOrgContext<T>(fn: (ctx: { orgId: string; user: User }) => Promise<T>): Promise<T> {
const { user, session } = await requireAuth();
const orgId = session.activeOrganizationId;
if (!orgId) throw new AuthError('no_org_context');
return fn({ orgId, user });
}
function safeNext(next: string | null): string {
if (!next) return '/';
if (next.startsWith('//')) return '/';
if (!next.startsWith('/')) return '/';
return next;
}
// src/lib/auth/provider.ts
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { organization, admin, magicLink, twoFactor } from 'better-auth/plugins';
import { db } from '@/db';
import { customAC, roles } from './access-control';
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: 'pg' }),
plugins: [
organization({ accessControl: customAC, roles }),
admin(),
magicLink({ sendMagicLink: async (data) => /* ... */ }),
twoFactor(),
],
});
## Restated request
<one sentence>
## Provider decision
- Picked: <Better Auth / Supabase / Clerk>
- Reason: <which criterion>
- Existing in project: <yes/no — if yes, defer; if no, proposed>
## Wrapper interface
- Status: <exists / will create>
- Files: src/lib/auth/index.ts, src/lib/auth/provider.ts, src/lib/auth/access-control.ts
## Files to create or modify
<bulleted with paths>
## Code
<actual code, organized by file>
## Multi-tenancy check
- Org middleware: <wired>
- Domain queries filter by orgId: <yes/no — list any that don't>
## Security check
- safeNext on redirects: <yes>
- JWT signature verification: <yes — if Clerk/Supabase>
- Admin client wrapped: <yes>
- Hardcoded allowlists: <none / flagged>
## Open questions
<things the user should confirm>
orgId from request body. Always from session.safeNext validation on redirect params.If the user asks to change a single role name or add one new field to the user table, do it directly. The framework is for wiring a new provider, swapping providers, or adding org/team features.
What SKILL.md sets; muted values are Claude Code's defaults
47 skills in this plugin
/factory-animationMotion discipline distilled across builds. Attention as a fixed per-viewport budget, figure/ground separation (calm the ground, load motion into the figure), one focal point of motion per screen, diegetic-over-decorative test, trigger-on-intent-then-settle over perpetual loops, and the prefers-reduced-motion fallback. Recipe pairs Astro with a Remotion video kit (rendered assets in public/). Read whenever you add motion to a marketing surface or any page where movement competes with reading. Paired with factory-design, which owns the static visual vocabulary motion sits on top of./factory-apiAPI conventions for both server actions and tRPC builds. Covers the decision between them, per-mutation Zod input schemas, central router composition, pagination shape, multi-field search via Drizzle `ilike` + `or()`, mutation lifecycle hooks, conditional query enabling, stale-time defaults, error response shape and custom error class taxonomy, mutation-boundary audit logging, fetch adapter for tRPC routes. Read when designing or implementing any data-mutation endpoint./factory-api-route-engineerUse when designing or implementing API endpoints — server actions, tRPC procedures, REST routes for external consumers. Carries the factory's API conventions — the server actions vs tRPC decision, procedure tier stacking, per-mutation Zod schemas, central router composition with manual registration, pagination (limit/offset/orderBy default; cursor only when needed), multi-field search via `ilike` + `or()`, aggregated stats in list queries, mutation lifecycle hooks, stale-time defaults, custom error class taxonomy, fetch adapter for tRPC in App Router. Outputs endpoints that fit the house style — not bespoke per-route handlers.npx claudepluginhub nonlinear-xyz/factory-kit --plugin factory-kitOther plugins' skills for the same job