About better-auth-core
better-auth-core is a TypeScript skill for configuring Better Auth, wiring server and client instances, and using sessions and server APIs safely. It covers pluggable database choices and stateless sessions.
Key features
- 01Configure Better Auth instances
- 02Wire server handlers and clients
- 03Use sessions and server APIs
- 04Choose database drivers or adapters
- 05Infer TypeScript types
Use cases
- 01Set up authentication from environment variables
- 02Add a database or use stateless sessions
- 03Read sessions on client or server
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ bobmatnyc/ claude-mpm-skills --skill better-auth-coreAfter installing, type/better-auth-corein Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
metadata.jsonreferences/client-server.mdsetup-database.mdtypescript.mdDetails
From the project READMEBetter Auth Core (TypeScript)
Goals
- Set up a Better Auth instance with environment variables and data layer wiring.
- Wire server handlers and a client instance.
- Use sessions and server-side API methods safely.
- Keep data-layer choices pluggable (drivers or adapters).
Quick start
- Install
better-auth. - Set
BETTER_AUTH_SECRET(32+ chars) andBETTER_AUTH_URL. - Create
auth.tsand exportauth. - Provide
database(driver or adapter) or omit for stateless sessions. - Mount a handler (
auth.handleror a framework helper). - Create a client with
createAuthClient.
import { betterAuth } from "better-auth";
export const auth = betterAuth({
database: myDatabaseOrAdapter, // driver or adapter; omit for stateless mode
emailAndPassword: { enabled: true },
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
});
Core setup checklist
- Export the instance as
auth(or default export) so helpers find it. - Keep
BETTER_AUTH_URLin sync with the public base URL. - Pass the full base URL to the client if you change the
/api/authbase path. - Add database migrations before enabling plugins that require tables.
Server API usage
- Call server endpoints via
auth.api.*with{ body, headers, query }. - Use
asResponse: trueif you need aResponseobject. - Use
returnHeaders: trueto accessSet-Cookieheaders.
import { auth } from "./auth";
const session = await auth.api.getSession({
headers: request.headers,
});
const response = await auth.api.signInEmail({
body: { email, password },
asResponse: true,
});
Session access
- Client:
authClient.useSession()orauthClient.getSession(). - Server:
auth.api.getSession({ headers }).
TypeScript tips
- Infer types with
auth.$InferandauthClient.$Infer. - Use
inferAdditionalFieldson the client when you extend the user schema.
References
toolchains/platforms/auth/better-auth/better-auth-core/references/setup-database.mdtoolchains/platforms/auth/better-auth/better-auth-core/references/client-server.mdtoolchains/platforms/auth/better-auth/better-auth-core/references/typescript.md
Comments
Markdown supported