better-auth-core

Better Auth Core (TypeScript)

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "better-auth-core" with this command: npx skills add bobmatnyc/claude-mpm-skills/bobmatnyc-claude-mpm-skills-better-auth-core

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 BETTER_AUTH_SECRET (32+ chars) and BETTER_AUTH_URL .

  • Create auth.ts and export auth .

  • Provide database (driver or adapter) or omit for stateless sessions.

  • Mount a handler (auth.handler or 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_URL in sync with the public base URL.

  • Pass the full base URL to the client if you change the /api/auth base 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: true if you need a Response object.

  • Use returnHeaders: true to access Set-Cookie headers.

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() or authClient.getSession() .

  • Server: auth.api.getSession({ headers }) .

TypeScript tips

  • Infer types with auth.$Infer and authClient.$Infer .

  • Use inferAdditionalFields on the client when you extend the user schema.

References

  • toolchains/platforms/auth/better-auth/better-auth-core/references/setup-database.md

  • toolchains/platforms/auth/better-auth/better-auth-core/references/client-server.md

  • toolchains/platforms/auth/better-auth/better-auth-core/references/typescript.md

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

nodejs-backend-typescript

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

jest-typescript

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

github-actions

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

golang-cli-cobra-viper

No summary provided by upstream source.

Repository SourceNeeds Review