
Better Auth Integrations
- 246 installs
- 63 repo stars
- Updated July 18, 2026
- bobmatnyc/claude-mpm-skills
Connect Better Auth to OAuth providers, databases, email, and session storage for secure login in full-stack apps.
About
Covers Better Auth integration patterns for SaaS and API apps: wiring OAuth providers, database adapters, email flows, and session configuration into Next.js, Express, or similar stacks with secure defaults.
- OAuth and social providers
- Database session adapters
- Email and magic-link hooks
- Framework route mounting
- Production session config
Better Auth Integrations by the numbers
- 246 all-time installs (skills.sh)
- Ranked #1,568 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Data as of Aug 1, 2026 (Skillselion catalog sync)
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill better-auth-integrationsAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 246 |
|---|---|
| repo stars | ★ 63 |
| Last updated | July 18, 2026 |
| Repository | bobmatnyc/claude-mpm-skills ↗ |
What it does
Connect Better Auth to OAuth providers, databases, email, and session storage for secure login in full-stack apps.
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()],
});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.mdtoolchains/platforms/auth/better-auth/better-auth-integrations/references/frameworks.md
{
"name": "better-auth-integrations",
"version": "1.0.0",
"category": "toolchain",
"toolchain": null,
"tags": [
"better-auth",
"auth",
"integrations",
"nextjs",
"sveltekit",
"remix",
"express",
"hono",
"cloudflare"
],
"entry_point_tokens": 160,
"full_tokens": 1103,
"related_skills": [
"better-auth-core",
"better-auth-authentication",
"better-auth-plugins"
],
"author": "Claude MPM",
"license": "MIT",
"platform": "auth"
}
Framework handler recipes
SvelteKit
import { auth } from "$lib/auth";
import { svelteKitHandler } from "better-auth/svelte-kit";
import { building } from "$app/environment";
export async function handle({ event, resolve }) {
return svelteKitHandler({ event, resolve, auth, building });
}Remix
import { auth } from "~/lib/auth.server";
import type { LoaderFunctionArgs, ActionFunctionArgs } from "@remix-run/node";
export async function loader({ request }: LoaderFunctionArgs) {
return auth.handler(request);
}
export async function action({ request }: ActionFunctionArgs) {
return auth.handler(request);
}Express
import express from "express";
import { toNodeHandler } from "better-auth/node";
import { auth } from "./auth";
const app = express();
app.all("/api/auth/*", toNodeHandler(auth));
app.use(express.json());Hono
import { Hono } from "hono";
import { auth } from "./auth";
const app = new Hono();
app.on(["POST", "GET"], "/api/auth/*", (c) => auth.handler(c.req.raw));Cloudflare Workers
import { auth } from "./auth";
export default {
async fetch(request: Request) {
const url = new URL(request.url);
if (url.pathname.startsWith("/api/auth")) {
return auth.handler(request);
}
return new Response("Not found", { status: 404 });
},
};Next.js integration details
API route handler
App Router:
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";
export const { GET, POST } = toNextJsHandler(auth);Pages Router:
import { auth } from "@/lib/auth";
import { toNodeHandler } from "better-auth/node";
export const config = { api: { bodyParser: false } };
export default toNodeHandler(auth.handler);Server actions and RSC
Use auth.api with headers() to access the session.
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
export async function ServerComponent() {
const session = await auth.api.getSession({
headers: await headers(),
});
if (!session) return <div>Not authenticated</div>;
return <div>Welcome {session.user.name}</div>;
}Cookie handling in server actions
Add nextCookies as the last plugin so server actions set cookies:
import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
export const auth = betterAuth({
plugins: [nextCookies()],
});Middleware / proxy
For Next.js 16+ proxy, avoid full DB checks in edge paths unless you opt into Node runtime.
Cookie-only check:
import { NextResponse } from "next/server";
import { getSessionCookie } from "better-auth/cookies";
export async function proxy(request: Request) {
const sessionCookie = getSessionCookie(request);
if (!sessionCookie) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}