mcpField
B
better-auth-integrations

better-auth-integrations

github.com/bobmatnycDevelopment78358 installsUpdated 15w ago
Repository

About better-auth-integrations

A skill for integrating Better Auth handlers into web frameworks, with examples for Next.js App Router and Pages Router. It focuses on route setup and correct cookie and header handling in server-side rendering and server actions.

Key features

  1. 01Mount handlers at auth routes
  2. 02Use framework-specific handler helpers
  3. 03Configure Next.js App Router and Pages Router
  4. 04Handle cookies in server actions
  5. 05Keep server and client base paths aligned

Use cases

  1. 01Add Better Auth routes to a Next.js app
  2. 02Configure auth handling in server actions
  3. 03Avoid cookie and body-parser integration issues

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill better-auth-integrations

After installing, type/better-auth-integrationsin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

metadata.json
references/
frameworks.md
nextjs.md

Details

From the project README

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
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { GET, POST } = toNextJsHandler(auth);
Next.js Pages Router
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.

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

Comments

Markdown supported