Research-mind toolchains-platforms-auth-better-auth-better-auth-core
Better Auth Core (TypeScript)
install
source · Clone the upstream repo
git clone https://github.com/MacPhobos/research-mind
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/MacPhobos/research-mind "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/toolchains-platforms-auth-better-auth-better-auth-core" ~/.claude/skills/macphobos-research-mind-toolchains-platforms-auth-better-auth-better-auth-core && rm -rf "$T"
manifest:
.claude/skills/toolchains-platforms-auth-better-auth-better-auth-core/skill.mdsource content
Better 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
(32+ chars) andBETTER_AUTH_SECRET
.BETTER_AUTH_URL - Create
and exportauth.ts
.auth - Provide
(driver or adapter) or omit for stateless sessions.database - Mount a handler (
or a framework helper).auth.handler - 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
(or default export) so helpers find it.auth - Keep
in sync with the public base URL.BETTER_AUTH_URL - Pass the full base URL to the client if you change the
base path./api/auth - Add database migrations before enabling plugins that require tables.
Server API usage
- Call server endpoints via
withauth.api.*
.{ body, headers, query } - Use
if you need aasResponse: true
object.Response - Use
to accessreturnHeaders: true
headers.Set-Cookie
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:
orauthClient.useSession()
.authClient.getSession() - Server:
.auth.api.getSession({ headers })
TypeScript tips
- Infer types with
andauth.$Infer
.authClient.$Infer - Use
on the client when you extend the user schema.inferAdditionalFields
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