Authdog

Next.js

Authentication for Next.js, done right

Add login, sessions, and route protection to your App Router app in minutes. Authdog handles the cookies, token refresh, and edge checks so you can focus on your product, not your auth plumbing.

5 min to a protected route
Drop in the middleware, wrap your app, and your routes are guarded. Most teams ship login the same afternoon.
No client-side tokens
Sessions live in secure HTTP-only cookies and are read on the server. There's no token for client JavaScript to leak.
Session check at the edge
Middleware verifies the session before the page renders, so unauthorized users never see protected content.
Typed sessions
Autocomplete for sessions, claims, and roles catches auth mistakes at build time, not in production.

Drop-in middleware

// middleware.ts
import { withAuth } from "@authdog/nextjs"

export default withAuth({
  publicRoutes: ["/", "/pricing"],
  loginPage: "/login",
})

Read the session on the server

// app/dashboard/page.tsx
import { getSession } from "@authdog/nextjs/server"

export default async function Page() {
  const session = await getSession()

  return <h1>Welcome, {session.user.name}</h1>
}

Built for the App Router

Everything Next.js apps need

From middleware to Server Components, Authdog fits the Next.js model instead of fighting it.

01

App Router & RSC

First-class support for Next.js 14+ App Router. Read the session in Server Components, Client Components, and Server Actions with a single API.

  • Server and Client Components
  • Server Actions
02

Middleware route protection

Guard whole route trees from the edge. Redirect unauthenticated users before a page ever renders, with no flash of protected content.

  • Whole route trees
  • No protected content flash
03

API & Route Handlers

Validate sessions and access tokens inside Route Handlers and API routes so your server endpoints stay protected end to end.

  • Route Handlers
  • Access token validation
04

Typed SDK

A fully typed SDK with autocomplete for sessions, claims, and roles. Catch auth mistakes at build time, not in production.

  • Sessions, claims, and roles
  • Build-time safety
05

Automatic token refresh

Sessions are refreshed silently using secure, HTTP-only cookies. No token plumbing, no expiry edge cases to handle yourself.

  • Silent refresh
  • HTTP-only cookies
06

Edge-ready

Runs on the Edge and Node.js runtimes alike. Verify identity close to the user with sub-millisecond session checks.

  • Edge and Node runtimes
  • Sub-millisecond checks
01

Install

Add @authdog/nextjs-app and your environment keys.

02

Add middleware

Export withAuth from middleware.ts and list your public routes.

03

Read the session

Call getSession() in Server Components, Actions, and Route Handlers.

Add auth to your Next.js app.

Install the SDK, wrap your app, and protect your routes today. Free to start, with secure defaults built in.