Skip to content
Agentmart
Submit a tool

betterauth

BetterAuth integration patterns — setup, session management, OAuth providers, middleware protection, and security best practices for authentication in…

Skill by Satcomx00-x00

IndexedMIT
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/satcomx00-x00-betterauth

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

BetterAuth integration patterns — setup, session management, OAuth providers, middleware protection, and security best practices for authentication in TypeScript/Next.js applications.

Use cases: frontend, security

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/betterauth

What's inside

Skill name
betterauth
Description
BetterAuth integration patterns — setup, session management, OAuth providers, middleware protection, and security best practices for authentication in TypeScript/Next.js applications.
License
MIT
Metadata
author: Satcomx00-x00 · version: 1.0.0
Instructions
248 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# betterauth

BetterAuth integration patterns — setup, session management, OAuth providers, middleware protection, and security best practices for authentication in TypeScript/Next.js applications.

## Instructions

Apply these practices when integrating BetterAuth into your application:

### Setup & Configuration

Create a single authoritative auth instance and export typed helpers from it:

```ts
// lib/auth.ts
import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import { db } from './db';

export const auth = betterAuth({
  database: prismaAdapter(db, { provider: 'postgresql' }),
  emailAndPassword: { enabled: true },
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    },
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    },
  },
  session: {
    expiresIn: 60 * 60 * 24 * 7,        // 7 days
    updateAge: 60 * 60 * 24,             // refresh session if older than 1 day
    cookieCache: { enabled: true, maxAge: 60 * 5 }, // 5-minute client cache
  },
  trustedOrigins: [process.env.NEXT_PUBLIC_APP_URL!],
});

// Export typed client helpers
export type Session = typeof auth.$Infer.Session;
```

### API Route Handler

Mount the BetterAuth catch-all handler at `app/api/auth/[...all]/route.ts`:

```ts
// app/api/auth/[...all]/route.ts
import { auth } from '@/lib/auth';
import { toNextJsHandler } from 'better-auth/next-js';

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

### Client-Side Auth Client

Create a single client instance to use across Client Components:

```ts
// lib/auth-client.ts
import { createAuthClient } from 'better-auth/react';

export const authClient = createAuthClient({
  baseURL: process.env.NEXT_PUBLIC_APP_URL!,
});

export const { signIn, signOut, signUp, useSession } = authClient;
```

### Session Access

**Server Component:**
```ts
import { auth } from '@/lib/auth';
import { headers } from 'next/headers';

export async function getServerSession() {
  const session = await auth.api.getSession({ headers: await headers() });
  return session;
}
```

**Client Component:**
```tsx
'use client';
import { useSession } from '@/lib/auth-client';

export function UserAvatar() {
  const { data: session, isPending } = useSession();
  if (isPending) return <Skeleton />;
  if (!session) return null;
  return <img src={session.user.image ?? ''} alt={session.user.name} />;
}
```

### Route Protection

Protect routes at the middleware layer to avoid unnecessary page renders for unauthenticated users:

```ts
// middleware.ts
import { NextRequest, NextResponse } from 'next/server';
import { auth } from '@/lib/auth';

const PROTECTED = ['/dashboard', '/settings', '/api/protected'];

export async function middleware(req: NextRequest) {
  const isProtected = PROTECTED.some(path => req.nextUrl.pathname.startsWith(path));
  if (!isProtected) return NextResponse.next();

  const session = await auth.api.getSession({ headers: req.headers });
  if (!session) {
    const loginUrl = new URL('/login', req.url);
    loginUrl.searchParams.set('callbackUrl', req.nextUrl.pathname);
    return NextResponse.redirect(loginUrl);
  }

  return NextResponse.next();

From Satcomx00-x00/skills-db, MIT.

More from Satcomx00-x00/skills-db

Signals

Stars
0
Forks
0
Open issues
0
Last commit (this folder)
Apr 13, 2026 (6 months ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.0.0
License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Satcomx00-x00

Cite this page

betterauth skill. Agent Mart. https://agentmart.dev/skills/satcomx00-x00-betterauth (last updated 2026-10-24)