Skip to main content
skill CX Codex

better-auth-integrations — Claude Code skill: how to install

Configures Better Auth route handlers in TypeScript web frameworks like Next.js, Remix, Hono, and Express. Solves cookie and header forwarding for SSR and server actions.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add bobmatnyc/claude-mpm-skills --skill better-auth-integrations -a claude-code
Open on GitHub

What better-auth-integrations does

This skill gives your coding agent reference patterns for integrating Better Auth into TypeScript projects. It targets Next.js App Router and Pages Router, Remix, SvelteKit, Express, and Hono. The primary objective is wiring the /api/auth/* catch-all endpoint without header or cookie issues during SSR.

The skill specifies official helper functions for each environment. Next.js App Router mounts routes through toNextJsHandler(auth). Pages Router endpoints wrap auth.handler using toNodeHandler. When Next.js server actions handle authentication, the skill requires adding the nextCookies() plugin from better-auth/next-js.

Running a body parser before Better Auth breaks incoming authentication payloads. Pages Router routes must set bodyParser: false. Client and server paths must match exactly.

What it helps with

  • mount a catch-all /api/auth/* handler in Next.js App Router
  • configure Next.js Pages Router authentication with bodyParser disabled
  • handle session cookies in Next.js server actions via nextCookies
  • align authentication base paths between client and server

Example prompts for the agent

  • Mount Better Auth handlers in Next.js App Router under /api/auth/[...all]/route.ts
  • Set up Better Auth inside Next.js Pages Router and disable the default body parser
  • Configure the nextCookies plugin in Better Auth so server actions can write cookies

How to install better-auth-integrations

1Skills CLI (Vercel)

npx skills add bobmatnyc/claude-mpm-skills --skill better-auth-integrations -a claude-code

2Manually: put the files in place

~/.claude/skills/better-auth-integrations/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/better-auth-integrations/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about better-auth-integrations

How to install better-auth-integrations in Claude Code?

Run npx skills add bobmatnyc/claude-mpm-skills --skill better-auth-integrations -a claude-code in your terminal. The skill file is placed at ~/.claude/skills/better-auth-integrations/SKILL.md.

What does better-auth-integrations do?

It provides coding models with setup rules and code snippets for integrating Better Auth into Next.js, Remix, SvelteKit, Express, and Hono. It ensures /api/auth/* endpoints forward cookies and headers properly during SSR.

Why must bodyParser be disabled in Next.js Pages Router with Better Auth?

Better Auth parses incoming request bodies on its own. If the Next.js built-in body parser processes the payload first, the auth handler fails to read the request.

Source text

SKILL.md · MIT
---
name: better-auth-integrations
description: Better Auth framework integrations for TypeScript. Use when wiring route handlers in Next.js, SvelteKit, Remix, Express, Hono, or other web frameworks.
user-invocable: false
disable-model-invocation: true
progressive_disclosure:
  entry_point:
    summary: "Better Auth framework integrations for TypeScript. Use when wiring route handlers in Next.js, SvelteKit, Remix, Express, Hono, or other web frameworks."
    when_to_use: "When implementing authentication, authorization, or security."
    quick_start: "1. Review the core concepts below. 2. Apply patterns to your use case. 3. Follow best practices for implementation."
  references:
    - frameworks.md
    - nextjs.md
---
# Better Auth Integrations

## Goals
- Mount the Better Auth handler at `/api/auth/*` (or a custom base path).
- Use framework helpers where available.
- Ensure cookies and headers flow correctly in SSR and server actions.

## Quick start
1. Create an `auth` instance (see `better-auth-core`).
2. Add a catch-all route for `/api/auth/*`.
3. Use a framework helper (or `auth.handler`) to return a Response.

### Next.js App Router
```ts
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { GET, POST } = toNextJsHandler(auth);
```

### Next.js Pages Router
```ts
import { auth } from "@/lib/auth";
import { toNodeHandler } from "better-auth/node";

export const config = { api: { bodyParser: false } };
export default toNodeHandler(auth.handler);
```

## Cookie handling in Next.js server actions
Use the `nextCookies` plugin so server actions set cookies correctly.

```ts
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";

export const auth = betterAuth({
  // ...config
  plugins: [nextCookies()],
});
```

## Guardrails
- Keep the base path consistent between server and client.
- Prefer framework helpers when available.
- Avoid running custom body parsers before the auth handler.

## References
- `toolchains/platforms/auth/better-auth/better-auth-integrations/references/nextjs.md`
- `toolchains/platforms/auth/better-auth/better-auth-integrations/references/frameworks.md`

© bobmatnyc · MIT · bobmatnyc/claude-mpm-skills

Similar skills

All skills for Backend and APIs →

From the same set125

stacked-prs A skill that walks the agent through building stacks of dependent pull requests, where each branch grows from the previous one instead of main. Useful when a large feature is split into phases. CX Codex +1 362installs better-auth-core A skill for wiring Better Auth into TypeScript apps: the instance, server handlers, client, and sessions. Useful when you need auth running without digging through docs. CX Codex +1 358installs homebrew-formula-maintenance Automates Homebrew formula updates for Python CLIs. It syncs PyPI releases, updates archive hashes, refreshes dependency resources, and runs tap audits. CX Codex +1 357installs reporting-pipelines A skill that fixes one pattern for report exports: collect data, normalize it, write CSV/JSON/Markdown with timestamped names into reports/. CX Codex +1 354installs better-auth-plugins Guides coding agents when configuring Better Auth plugins in TypeScript projects. Covers two-factor auth, passkeys, JWT, and schema migrations. CX Codex +1 352installs git-worktrees Teaches the agent to manage parallel Git branches using worktrees. Useful for stacked pull requests, urgent bugfixes, and isolated code reviews. CX Codex +1 351installs nextjs-core Guides AI coding agents through Next.js App Router conventions: server-first components, safe Server Actions, and explicit cache revalidation. CX Codex +1 348installs fastapi-local-dev A runbook skill for FastAPI: Uvicorn with reload during development, Gunicorn with UvicornWorker in production. CX Codex +1 347installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor