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
Next.js
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.
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
From middleware to Server Components, Authdog fits the Next.js model instead of fighting it.
First-class support for Next.js 14+ App Router. Read the session in Server Components, Client Components, and Server Actions with a single API.
Guard whole route trees from the edge. Redirect unauthenticated users before a page ever renders, with no flash of protected content.
Validate sessions and access tokens inside Route Handlers and API routes so your server endpoints stay protected end to end.
A fully typed SDK with autocomplete for sessions, claims, and roles. Catch auth mistakes at build time, not in production.
Sessions are refreshed silently using secure, HTTP-only cookies. No token plumbing, no expiry edge cases to handle yourself.
Runs on the Edge and Node.js runtimes alike. Verify identity close to the user with sub-millisecond session checks.
Add @authdog/nextjs-app and your environment keys.
Export withAuth from middleware.ts and list your public routes.
Call getSession() in Server Components, Actions, and Route Handlers.
Install the SDK, wrap your app, and protect your routes today. Free to start, with secure defaults built in.