/auth:create-authfrom auth
Scaffolds signin and signup authentication endpoints for a project. Detects existing stack and asks about framework, database/ORM, session strategy, and auth methods.
Ships in auth. 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.
Read when SKILL.md points to them.
You are scaffolding authentication (signin + signup) for the user's project.
Before asking any questions, scan the user's project to detect their stack:
next.config.*, package.json, go.mod, Cargo.toml, pyproject.toml, build.gradle*, pom.xml)prisma/schema.prisma, drizzle.config.*, alembic/, diesel.toml, ormconfig.*)Use what you find to pre-select the best options in the questions below. If the project clearly uses a specific stack, set that as the recommended option.
Use the AskUserQuestion tool to ask the user to make selections. Ask up to 3 questions in a single AskUserQuestion call so the user can answer everything at once.
Ask "Which language and framework are you using?" with header "Framework".
Pick the top 4 most relevant options based on what you detected in the project. If you detected the framework, put it first and mark it "(Recommended)". If you could not detect it, use these defaults:
The user can always pick "Other" to specify a different stack.
Ask "Which database and ORM/query layer?" with header "Database".
Again, pick the top 4 most relevant options based on the project. If detected, mark it "(Recommended)". Defaults:
Ask "How should sessions be managed?" with header "Sessions".
After the user answers the stack questions, use AskUserQuestion again to ask which additional auth features they want. Use multiSelect: true so they can pick multiple features at once.
Ask "Which authentication methods do you want to add?" with header "Auth methods". Set multiSelect to true.
Ask "Which security features do you want?" with header "Security". Set multiSelect to true.
Ask "Any additional capabilities?" with header "Extras". Set multiSelect to true.
references/features/mcp-server.md for the two modes."Do not write any code until the user has answered all questions. Once you have their selections, proceed to Step 5.
Generate the core auth (schema + endpoints below) plus any selected features. For each selected feature, read the matching reference file from references/features/ to get the schema additions, endpoint specs, and implementation details.
Dependencies:
references/features/kv-cache.md and generate the KV cache module first — rate limiting depends on it. The KV cache is a general-purpose utility that other features can also use, so generate it as a standalone module./oauth/register, /oauth/authorize, and /oauth/token endpoints need it. Confirm with the user before generating; if they decline, leave a TODO comment at each endpoint pointing at the rate-limiting feature.| Feature | Reference file |
|---|---|
| Email OTP | references/features/email-otp.md |
| Magic Link | references/features/magic-link.md |
| Phone Number | references/features/phone-number.md |
| Passkey | references/features/passkey.md |
| Two-Factor Auth | references/features/two-factor.md |
| Captcha | references/features/captcha.md |
| Password Breach | references/features/password-breach.md |
| Rate Limiting | references/features/rate-limiting.md |
| KV Cache | references/features/kv-cache.md |
| Multi-Session | references/features/multi-session.md |
| Username Auth | references/features/username.md |
| Organization/Teams | references/features/organization.md |
| API Keys | references/features/api-key.md |
| MCP Server | references/features/mcp-server.md |
Generate the following core auth using the schema and endpoint specs below.
Adapt everything to the user's language/framework idioms:
email_verified (snake_case) in Python/Go/Rust, emailVerified (camelCase) in JS/TS, EmailVerified (PascalCase) in C#std::string in C++, String in Rust/Java, string in Go/TS)uuid.New() (Go), Uuid::new_v4() (Rust), crypto.randomUUID() (JS), uuid4() (Python), boost::uuids::random_generator() (C++), etc.bcrypt (Go/JS/Python), argon2 (Rust), libsodium (C/C++), etc.Create these tables/models:
User
| Field | Type | Constraints |
|---|---|---|
| id | string | primary key |
| string | unique, not null (store the canonical form — see sign-up) | |
| name | string | nullable |
| image | string | nullable |
| emailVerified | boolean | default false |
| createdAt | datetime | default now |
| updatedAt | datetime | auto-update |
Session
| Field | Type | Constraints |
|---|---|---|
| id | string | primary key |
| userId | string | foreign key -> User, not null |
| token | string | unique, not null |
| expiresAt | datetime | not null |
| ipAddress | string | nullable |
| userAgent | string | nullable |
| createdAt | datetime | default now |
ipAddress and userAgent power the "signed-in devices" list (see the Multi-Session feature) and security-notification emails.
Account
| Field | Type | Constraints |
|---|---|---|
| id | string | primary key |
| userId | string | foreign key -> User, not null |
| providerId | string | not null (e.g. "credential") |
| accountId | string | not null (provider-side user id; = userId for "credential") |
| passwordHash | string | nullable |
| createdAt | datetime | default now |
| updatedAt | datetime | auto-update |
Add a unique constraint on (providerId, accountId). Account lookups must always filter by that full tuple — never by accountId alone — so that OAuth providers added later cannot collide across ID spaces (see references/pitfalls/oauth-account-linking.md).
VerificationToken
| Field | Type | Constraints |
|---|---|---|
| id | string | primary key |
| userId | string | foreign key -> User, not null |
| purpose | string | not null ("verify-email" or "password-reset") |
| string | not null (the address the token was issued for, lowercased) | |
| tokenHash | string | unique, not null (SHA-256 of the raw token) |
| expiresAt | datetime | not null |
| consumedAt | datetime | nullable (set atomically on use) |
| createdAt | datetime | default now |
One table serves both flows; purpose keeps them apart and MUST be matched at redemption, or a reset link is redeemable as an email confirmation. Store only the hash — the raw token exists solely inside the emailed link. email records what the token proves, so a later address change cannot inherit the proof.
POST /api/auth/sign-up
{ email, password, name? }references/pitfalls/email-case-normalization.md[a-z0-9-] domain labels, exactly one @, ≤ 254 chars — no quotes, comments, angle brackets, commas, spaces, or non-ASCII (internationalized addresses only if the project deliberately supports them). Anything a mail library could re-parse into a different recipient — a(b)@x, "a"@x, x<attacker@evil>, a,b@x — is rejected rather than stored. Then validate password length (min 8 chars)ipAddress and userAgent on the session (User-Agent header; client IP from the trusted proxy header when deployed behind one, otherwise the socket address)"verify-email" token and send the confirmation link (see POST /api/auth/verify-email/send) — nothing else in a password-only build ever sets emailVerified, and an account that never proves an identifier is reaped. The duplicate-email path below creates no user, so it sends nothing and leaks nothing200 OK status and same response shape as a successful sign-up — do not return 409 or any error that reveals the email is taken. The response should be indistinguishable from a real sign-up. Implementation: attempt the insert, catch the unique constraint violation, hash the password anyway (to keep timing consistent), and return a fake success with a dummy user ID and token (that won't actually work as a session). This prevents attackers from discovering which emails are registered via the sign-up endpoint.POST /api/auth/sign-in
{ email, password }ipAddress and userAgent as in sign-up)GET /api/auth/session
Cache-Control: no-store once at the top of the handler — not at each return, and on the 401 as well as the 200. Otherwise the browser disk-caches this GET and keeps replaying "signed in" with the cached profile after the session has expired server-side.POST /api/auth/sign-out
POST /api/auth/verify-email/send
{ email } (canonicalize through the sign-up helper before lookup). Sign-up calls this internally on success; the route itself exists for resends"verify-email" tokens, then issue one: ≥32 bytes crypto-random, store only its SHA-256, expiresAt ≤ 24 hHost / X-Forwarded-Host, which the caller controls (reset-link poisoning; see references/pitfalls/oauth-redirect-request-url.md). Return 200 always, whether or not the address has an account — this endpoint must not reveal which addresses are registeredPOST /api/auth/verify-email/confirm
{ token }tokenHash, and require purpose = "verify-email", unexpired and unconsumedconsumedAt IS NULL, affected-rows checked (see references/pitfalls/single-use-token-race.md)emailVerified with a conditional write naming the token's email: UPDATE users SET email_verified = true WHERE id = $1 AND email = $2. Bind the address, and keep the flag itself out of this guard — this write records a proof and authorizes nothing destructive (see references/pitfalls/async-proof-value-binding.md). Zero rows means the address changed after the link was issued: discard the proofreferences/pitfalls/pre-account-hijack-strip.md)purpose token)POST /api/auth/password-reset/request
{ email } (canonicalize through the sign-up helper before lookup)verify-email/send: delete outstanding "password-reset" tokens, issue one with expiresAt ≤ 30 min, return 200 always, rate limit per address and per IPPOST /api/auth/password-reset/confirm
{ token, password }references/pitfalls/single-use-token-race.md)tokenHash, require purpose = "password-reset", unexpired and unconsumed, then consume it atomicallyemailVerified is still false, this reset is the first proof of mailbox control it has ever had: claim and strip it in the same transaction (see references/pitfalls/pre-account-hijack-strip.md) — everything on a never-verified row is unproven, including a planted passkey. Then write the new password into a freshly created credential Account, since the strip deleted the old onepasswordHash in placecrypto.randomUUID(), uuid.New(), Uuid::new_v4(), secrets.token_hex(), etc.)String.prototype.normalize, unicodedata.normalize, java.text.Normalizer), trim, lowercase — before any validation, lookup, or insert, and only the canonical form is stored. Validation runs on that string, never on the raw input: an address holding a fullwidth @ (U+FF20) passes a single-@ check on the raw bytes, then a mail library that normalizes recipients on its own sees two separators and delivers the sign-in link somewhere else (CWE-180, validate-before-canonicalize; Auth.js shipped it as GHSA-7rqj-j65f-68wh). The string you validated is the string you store and the string you hand to the mailer — which is also why the shape check is strict (lowercase dot-atom, see sign-up): a mailer that re-parses a(b)@x or x<attacker@evil> into a different recipient breaks that promise even after perfect canonicalization. Reject non-ASCII outright unless the project deliberately supports internationalized addresses — that is what closes the homoglyph hole in a language without stdlib NFKC (Go, Rust). Never compensate at query time with LOWER()/ILIKEemail column nullable. If it must stay non-null, mint the placeholder under the RFC 6761 reserved .invalid TLD, namespaced by source — <stable-identifier>@<source>.placeholder.invalid — never a domain anyone can receive mail at. A placeholder is never itself a proven identifier: leave emailVerified false permanently, never send mail to it, and let phoneVerified carry that account's proof. A row is phone-only — the qualifier the reaper and the enrolment gate below both hinge on — exactly when its email is NULL or such a *.placeholder.invalid placeholder; on a row holding a real address only emailVerified counts as proof. The create or find User step in Magic Link and Email OTP must skip placeholder rows — otherwise a magic link requested for a guessed placeholder address signs the attacker in as that user. Trading a placeholder for a real address requires a full verification cycle.UPDATE … WHERE consumed_at IS NULL / DELETE … RETURNING with the row count checked; in a KV store it is getAndDelete, never get followed by delete. Counters that gate anything (attempt caps, lockouts, rate limits) are bumped with an atomic increment, never read-modify-write — see references/pitfalls/single-use-token-race.md and the interface in references/features/kv-cache.mdemailVerified is read as an authorization input (references/features/organization.md gates invitation acceptance on it, and the enrolment gate below turns on it), so it is set at exactly one kind of moment — proven control of the mailbox: the core verify-email/confirm endpoint, a completed password reset, or a successful magic-link / email-OTP verification. Never set it from an unverified IdP claim. Then, via a scheduled job, delete the accounts that have proven no primary identifier at all — no emailVerified, and phoneVerified rescues a row only when that row is phone-only — on a short TTL (24–72 hours, and never shorter than the verification link's own expiry). A row holding a real, unverified address is reaped even if phoneVerified is true, or the job stops clearing exactly what it exists to clear: an unverified row holding an address is a reservation an attacker can make against any address, and it is what makes pre-account hijacking practical.emailVerified is still false, and that session proves possession of a password, not of the mailbox. Every endpoint that enrolls a durable authenticator — passkey registration, 2FA enable, API-key creation — must additionally require a proven primary identifier: emailVerified = true, or phoneVerified = true on a phone-only row as defined above. Otherwise whoever plants an account at an address its owner has not yet claimed leaves behind persistence that outlives the password.After generating all code, run the database migration automatically so the user doesn't hit "table does not exist" errors. Use the project's existing database driver/connection to execute the migration SQL.
For JS/TS projects using @neondatabase/serverless, the tagged-template sql function cannot run plain SQL strings. Use sql.query(statement) instead when executing migration statements programmatically.
Before generating code, read all files in references/pitfalls/ and follow their rules strictly. These are real bugs encountered in production.
| Pitfall | Reference file |
|---|---|
| API routes must catch DB errors | references/pitfalls/api-error-handling.md |
| Sign-up catch must not re-throw | references/pitfalls/signup-rethrow.md |
Auth helpers return null, never throw or a truthy error | references/pitfalls/auth-helpers-no-throw.md |
| Client must handle non-JSON | references/pitfalls/client-json-parsing.md |
| OAuth redirect must not use request.url | references/pitfalls/oauth-redirect-request-url.md |
| API key hash/gen must not be duplicated | references/pitfalls/api-key-shared-utils.md |
| MCP tokens must be audience-bound | references/pitfalls/mcp-token-audience.md |
| MCP must not pass tokens upstream | references/pitfalls/mcp-token-passthrough.md |
MCP 401 / recoverable 403 need resource_metadata | references/pitfalls/mcp-www-authenticate.md |
MCP .well-known must mount at root | references/pitfalls/mcp-discovery-mounting.md |
| Single-use tokens consume atomically | references/pitfalls/single-use-token-race.md |
| Emails canonicalize, then validate | references/pitfalls/email-case-normalization.md |
| Set-Cookie must survive error paths | references/pitfalls/set-cookie-on-error.md |
| OAuth links key on provider+account id | references/pitfalls/oauth-account-linking.md |
| Passwordless sign-in strips credentials | references/pitfalls/pre-account-hijack-strip.md |
| Async proofs bind to the value proven | references/pitfalls/async-proof-value-binding.md |
| NULL owner must deny, not skip the gate | references/pitfalls/nullable-owner-gate.md |
| Authorize the value the handler acts on | references/pitfalls/authorization-must-match-the-action.md |
| Secrets are redeemable for one purpose only | references/pitfalls/cross-purpose-token-confusion.md |
Full working examples are in the references/ directory alongside this skill. Use the matching reference as a starting point and adapt to the user's specific setup:
| File | Stack |
|---|---|
nextjs-drizzle.ts | Next.js App Router + Drizzle + PostgreSQL |
express-prisma.ts | Express + Prisma + PostgreSQL |
go-chi.go | Go + Chi + database/sql + PostgreSQL |
fastapi-sqlalchemy.py | FastAPI + SQLAlchemy + PostgreSQL |
axum-sqlx.rs | Rust + Axum + sqlx + PostgreSQL |
spring-boot.kt | Kotlin + Spring Boot + JPA + PostgreSQL |
If the user's stack doesn't match any reference, use the closest one as a structural guide and adapt idioms accordingly.
references/axum-sqlx.rs (opens in a new tab)references/express-prisma.ts (opens in a new tab)references/fastapi-sqlalchemy.py (opens in a new tab)references/features/api-key.md (opens in a new tab)references/features/captcha.md (opens in a new tab)references/features/email-otp.md (opens in a new tab)references/features/kv-cache.md (opens in a new tab)references/features/magic-link.md (opens in a new tab)references/features/mcp-server.md (opens in a new tab)references/features/multi-session.md (opens in a new tab)references/features/organization.md (opens in a new tab)references/features/passkey.md (opens in a new tab)references/features/password-breach.md (opens in a new tab)references/features/phone-number.md (opens in a new tab)references/features/rate-limiting.md (opens in a new tab)references/features/two-factor.md (opens in a new tab)references/features/username.md (opens in a new tab)references/go-chi.go (opens in a new tab)references/nextjs-drizzle.ts (opens in a new tab)references/pitfalls/api-error-handling.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (himself65/auth-spec) — no native marketplace selected
npx claudepluginhub p/himself65-auth2 skills in this plugin
Other plugins' skills for the same job