auth
Skill1 starsChanged 3 months agoMITView on GitHub
Authentication with Better Auth 1.6, the locked stack default (Auth.js/NextAuth is maintenance-mode legacy) — server config with the Drizzle adapter, CLI-generated schema, client hooks, optimistic route protection in proxy.ts (Next 16, never middleware.ts), authoritative session checks in RSC and in every mutation, and a sign-in page styled to the design system, never the default unstyled form. Invoke during the backend phase whenever the brief needs accounts, protected pages, or roles, or the user says "auth", "login", "sign in", "sign up", "sessions", "protected routes", or "user accounts".
- Reads credentials
- Installs packages
17 other projects use a version of this.
Adopted by
Most recently taken up by
- crbnos/carbontheir own version, first seen Oct 4, 2026
- vercel-labs/hatcherytheir own version, first seen Sep 25, 2026
- microsoft/apmtheir own version, first seen Sep 16, 2026
- zyphr-labs/bounty-harnesstheir own version, first seen Aug 26, 2026
- SpiderIQ/skillstheir own version, first seen Aug 20, 2026
- silvioventre/lovable-skillstheir own version, first seen Aug 18, 2026
Used with
Projects with it also use test and deploy.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.Other versions17 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 17
- openai/plugins★ 7.3ksame name
- microsoft/apm★ 3.9ksame name
- crbnos/carbon★ 2.7ksame name
- vercel/vercel-plugin★ 297same name
- maxwell2732/claudecode-research-harness-workflow★ 40same name
- lightpointventures/claude-code-starter★ 36same name
- YepAPI/skills★ 8same name
- vercel-labs/hatchery★ 7same name
- MartinOlivero/saas-builder★ 4same name
- silvioventre/lovable-skills★ 4same name
7 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository79 other files it gives its agents.
- ultrawebSkill
- analyticsSkill
- animejsSkill
- api-designSkill
- app-structureSkill
- assetsSkill
- award-canonSkill
- briefSkill
- buttonsSkill
- cardsSkill
- cartSkill
- checkpointSkill
- colorSkill
- command-paletteSkill
- component-apiSkill
- consentSkill
- content-cmsSkill
- copywritingSkill
- databaseSkill
- data-displaySkill
- data-fetchingSkill
- depthSkill
- directionSkill
- emailSkill
- faqSkill
- feature-sectionsSkill
- footerSkill
- formsSkill
- gate-accessibilitySkill
- gate-antislopSkill
- gate-codeSkill
- gate-contentSkill
- gate-performanceSkill
- gate-responsiveSkill
- gate-visualSkill
- handoffSkill
- heroSkill
- hidden-craftSkill
- i18nSkill
- iconsSkill
- identitySkill
- imagerySkill
- iterateSkill
- layout-gridSkill
- marginaliaSkill
- media-optimizationSkill
- micro-interactionsSkill
- mockupSkill
- motion-languageSkill
- navigationSkill
- overlaysSkill
- page-transitionsSkill
- paymentsSkill
- physicsSkill
- previewSkill
- pricingSkill
- print-craftSkill
- product-detailSkill
- retrofitSkill
- routingSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.
0
Common
Most of the 14 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Read BRIEF.md: which pages are protected, which sign-in methods (email+password?
- Very specific: line 97
Every mutating server action and route handler re-checks the session itself — a forged request never meets proxy.ts, and a page-level check …
- Distinctive: line 113
Default unstyled sign-in form.
“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
auth — Better Auth, designed sign-in
Stage: Phase 7 (Backend) - Reads: design/BRIEF.md, design/SYSTEM.md, design/DIRECTION.md, db/schema.ts - Writes: lib/auth.ts, lib/auth-client.ts, app/api/auth/[...all]/route.ts, proxy.ts, app/(auth)/* pages
Standard
Invisible when it works, designed when it shows. Sessions are verified on the server where the data lives — proxy redirects are UX, not security. The sign-in page consumes SYSTEM.md tokens and gets hero-level craft: it is often the second impression the site makes. Better Auth 1.6 without discussion; NextAuth requires written justification.
Default and legacy
Better Auth 1.6 is the default for every new build. Auth.js/NextAuth entered maintenance mode 2025-09-22 — the Better Auth team maintains it for security patches only and recommends Better Auth for greenfield. NextAuth v5 never left beta (5.0.0-beta.31).
NextAuth v5 beta remains acceptable in exactly two cases: the project already runs it and this is an iteration, or the brief hard-requires a provider/adapter that exists only in the Auth.js ecosystem. Then use the legacy pattern — auth.ts exporting const { auth, handlers } = NextAuth({...}), app/api/auth/[...nextauth]/route.ts re-exporting handlers, proxy.ts re-exporting auth — and record the deviation plus reason in BRIEF.md.
Process
- Read BRIEF.md: which pages are protected, which sign-in methods (email+password? Google? magic link →
ultraweb:email), whether roles exist. No auth requirement → stop. Never bolt accounts onto a brochure site. npm i better-auth@1.6(the STACK.md-verified line).BETTER_AUTH_SECRET+BETTER_AUTH_URLinto.env. Server config inlib/auth.ts(below).npx auth@1.6 generate— the CLI pinned to the SAME 1.6.x line as the installed better-auth (they ship in lockstep; a floating CLI can emit a schema the installed lib doesn't match). Emits the Drizzle auth tables (user, session, account, verification). Merge intodb/schema.tsand migrate throughultraweb:database: one schema, one migration history.- Mount the handler and create the client (below).
- Protect in layers: proxy.ts cookie check for redirect UX, server-side session check where protected data renders, and a session re-check inside every mutating server action and route handler. All three, always.
- Build sign-in/sign-up as designed pages (rule below). Then verify the loop empirically: sign up → sign out → hit a protected page (must redirect) → sign in (must land back).
Server config, handler, client
// lib/auth.ts
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { nextCookies } from "better-auth/next-js";
import { db } from "@/db";
export const auth = betterAuth({
database: drizzleAdapter(db, { provider: "pg" }),
emailAndPassword: { enabled: true },
// socialProviders: only what BRIEF.md names — each one is env vars + a provider console to maintain
plugins: [nextCookies()], // keep last: lets server actions set session cookies
});// app/api/auth/[...all]/route.ts
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";
export const { GET, POST } = toNextJsHandler(auth);// lib/auth-client.ts
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient();
// client components: authClient.useSession(), authClient.signIn.email({ email, password }), authClient.signOut()Better Auth's adapter and plugin import paths evolve — the shapes above are the 1.6 line; verify against current docs at build time.
Route protection: two layers, never one
middleware.ts is deprecated in Next 16 — the file is proxy.ts, Node runtime. The proxy layer is OPTIMISTIC: cookie presence only, no DB hit, pure redirect UX.
// proxy.ts
import { NextRequest, NextResponse } from "next/server";
import { getSessionCookie } from "better-auth/cookies";
export function proxy(request: NextRequest) {
if (!getSessionCookie(request)) {
return NextResponse.redirect(new URL("/login", request.url));
}
return NextResponse.next();
}
export const config = { matcher: ["/dashboard/:path*", "/settings/:path*"] };The AUTHORITATIVE check lives where protected data renders:
// app/dashboard/page.tsx (RSC)
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
export default async function DashboardPage() {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) redirect("/login");
// session.user.id drives every query below
}Every mutating server action and route handler re-checks the session itself — a forged request never meets proxy.ts, and a page-level check doesn't cover it.
The sign-in page rule
The default unstyled form is banned — same severity as lorem ipsum. The sign-in page:
- Consumes SYSTEM.md tokens: type scale, accent, radius/shadow language, both themes designed.
- Picks a layout variant to match DIRECTION.md: centered card (SaaS default), split-screen with a brand panel that carries the signature move, or minimal full-page type-led form (editorial directions).
- Full states: focus-visible rings in the palette, inline zod validation on
ultraweb:formstiming, submit button with loading state, error copy in the site voice ("That email and password don't match." — never "Invalid credentials error"). - Social buttons follow provider brand rules but sit inside your radius and spacing system.
Anti-patterns
middleware.ts— deprecated; the file isproxy.tsauth.api.getSessioninside proxy.ts — a DB hit on every matched request; cookie check only there- Protection ONLY in proxy.ts — an optimistic redirect is not authorization; any mutation without its own check is an open door
- Default unstyled sign-in form; untouched shadcn card presented as "the auth page"
npm i next-authon greenfield without the written justification in BRIEF.md- Hand-rolled password hashing or session tokens
session?.userfrom a client hook trusted for anything security-relevant — client session state is display data
Worked example — Tidepool, gating the port-analytics app shell
Moved to references/example.md — read only when this build's case is genuinely ambiguous; the sections above are the decision material.
Composes with
Moved to references/composes.md — the handoff map; load it when orchestrating this skill against its neighbors.
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
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.

