One auth() works everywhere
Auth.js v5 (formerly NextAuth.js) ships a single auth() helper that runs in Server Components, Server Actions, Route Handlers, and the proxy. The mental model: "is there a session?" — same answer, same call site, no matter where you ask.
Setup
Install next-auth@beta, configure providers, export handlers + auth. Wire handlers as a Route Handler at app/api/auth/[...nextauth]/route.ts.
Where you'll call auth()
| Location | Pattern |
|---|---|
| Server Component | const session = await auth(); |
| Server Action | same |
| Route Handler | same |
| Proxy | wrap export: export const proxy = auth(req => { … }); |