bobmatnyc avatar

Better Auth Integrations

This handles the routing and framework-specific wiring for Better Auth in TypeScript projects. You'll reach for it when mounting authentication endpoints at `/api/auth/*` in Next.js (both App and Pages Router), SvelteKit, Remix, Express, or Hono. The main win is framework-specific helpers like `toNextJsHandler` that abstract away the boilerplate of converting Better Auth's handler into whatever your framework expects. One thing to watch: Next.js server actions need the `nextCookies` plugin or your session cookies won't set properly. The guardrails are simple: keep your base path consistent and don't run custom body parsers before the auth handler.

skills.sh installs
363
GitHub stars
79
last updated
Aug 21, 2026

Install

$ npx -y skills add bobmatnyc/claude-mpm-skills --skill better-auth-integrations --agent claude-code

Installs into .claude/skills of the current project.

Files

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()],
});

Sponsors

Details

Repository
github.com/bobmatnyc/claude-mpm-skills
Categories
Frontend Development, Backend & APIs
First seen
Jun 3, 2026

More from bobmatnyc/claude-mpm-skills

All 158
1bobmatnyc avatarheadlessuibobmatnyc/claude-mpm-skillsHeadless UI - Unstyled, fully accessible UI components for React and Vue with built-in ARIA patterns355skills.sh installs
2davila7 avatarartifacts-builderdavila7/claude-code-templatesSuite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for355skills.sh installs
3jezweb avatarauto-animatejezweb/claude-skillsZero-config animations for React, Vue, Solid, Svelte, Preact with @formkit/auto-animate (3.28kb). Prevents 15 documented errors including React 19 StrictMode bu355skills.sh installs
4bobmatnyc avatarenv-managerbobmatnyc/claude-mpm-skillsEnvironment variable validation, security scanning, and management for Next.js, Vite, React, and Node.js applications350skills.sh installs
5jezweb avatarcloudflare-turnstilejezweb/claude-skillsAdd bot protection with Turnstile (CAPTCHA alternative). Use when: protecting forms, securing login/signup, preventing spam, migrating from reCAPTCHA, integrati348skills.sh installs
6pproenca avataruniwindpproenca/dot-skillsUniwind best practices for React Native styling with Tailwind CSS. This skill should be used when writing, reviewing, or refactoring React Native code using Uni348skills.sh installs