AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Better Auth Nextjs Integration And Route Protection

skill-andrewsrigom-agent-skills-better-auth-nextjs-integration-and-route-protection · by andrewsrigom

Use when integrating Better Auth with Next.js App Router or Pages Router. Covers `toNextJsHandler`, auth route mounting, client setup, RSC and server action boundaries, proxy or middleware-based protection, and session checks across modern Next.js versions.

No reviews yet
0 installs
31 views
0.0% view→install

Install

$ agentstack add skill-andrewsrigom-agent-skills-better-auth-nextjs-integration-and-route-protection

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-andrewsrigom-agent-skills-better-auth-nextjs-integration-and-route-protection)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
5mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Better Auth Nextjs Integration And Route Protection? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Better Auth Next.js Integration And Route Protection

Use this skill when the Better Auth task is specifically about Next.js wiring.

Scope

  • App Router auth route setup
  • Pages Router auth route setup
  • toNextJsHandler and toNodeHandler
  • Next.js client setup for Better Auth
  • RSC and server action auth boundaries
  • route protection with proxy or middleware
  • cookie-based checks and session reads in Next.js

Default path

  1. Confirm whether the app is App Router or Pages Router.
  2. Mount the Better Auth handler in /api/auth/[...all] unless the app has a strong reason to customize it.
  3. Create the Better Auth client in a shared lib/auth-client boundary.
  4. Use Better Auth session APIs where the framework runtime allows them.
  5. For route protection, prefer the current Next.js runtime model:
  • proxy.ts for Next.js 16+
  • version-appropriate middleware or cookie checks for older releases
  1. Keep auth checks close to the route boundary and avoid duplicating them inside every page.

When to deviate

  • Customize the auth route only when an existing app convention or deployment constraint requires it.
  • Use Pages Router guidance only when the repo is actually Pages-based.
  • Fall back to version-appropriate middleware naming or cookie checks when the app is on an older Next.js line.
  • Move back to the Better Auth overview skill when the task is no longer specifically about Next.js wiring.

Guardrails

  • Do not mix App Router and Pages Router patterns in the same answer.
  • Use the correct handler adapter for the route type.
  • Keep auth route mounting and client base path aligned.
  • Prefer cookie-based checks or Better Auth APIs over ad hoc session parsing.
  • Next.js version differences matter; verify whether the app is on the proxy naming model.

Avoid

  • mixing App Router and Pages Router setup in one implementation path
  • scattering auth checks through page components instead of keeping them near route boundaries
  • hand-parsing session cookies when Better Auth or framework APIs already own that surface
  • ignoring the Next.js version when recommending proxy.ts vs older middleware patterns

Verification checklist

  • router type is confirmed as App Router or Pages Router
  • handler adapter and file location match the router type
  • auth route and client base path stay aligned
  • route protection lives at a deliberate boundary
  • Next.js version-specific guidance is correct for the target app

Common Routing Cues

  • Next.js Better Auth, toNextJsHandler, toNodeHandler, /api/auth/[...all], App Router, Pages Router, proxy.ts, middleware, protected dashboard, server action auth

Output Shape

When answering with this skill, prefer:

  • route file location
  • exact adapter choice
  • client file location
  • route-protection boundary
  • version-specific Next.js note when required

Official References

  • https://better-auth.com/docs/installation
  • https://better-auth.com/docs/integrations/next
  • https://better-auth.com/docs/basic-usage
  • https://better-auth.com/docs/concepts/api

Current snapshot

  • Checked against official docs on 2026-04-03
  • Current npm line verified live on 2026-04-03: better-auth@1.5.6
  • Next.js integration docs in scope: installation, Next integration, basic usage, and API concepts

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.