All integrations
NextJS
Frameworks

Authorization for Next.js applications

Integrate Cerbos authorization service with your Next.js application for fine-grained, low-maintenance access controls that scale from startup to enterprise.

Authorize server components

Authorize server components

Call Cerbos in server components and server actions to enforce permissions where data is fetched and mutations are processed

Context from the request

Context from the request

Pass session data, route parameters, and resource attributes from Next.js middleware or server context to Cerbos for attribute-based authorization decisions

Protect every layer

Protect every layer

Apply Cerbos checks in middleware for route-level gating, in server components for data access, and in API routes for backend enforcement

How Cerbos works with NextJS

Building authorization logic inside NextJS quickly becomes a maintenance burden. Hard-coded role checks scatter across controllers and middleware, and every permission change requires a code deploy.

Cerbos replaces scattered authorization logic with a single API call. You define fine-grained policies in YAML, and the Cerbos PDP evaluates them at request time using roles, attributes, and any context you provide.

With Cerbos your NextJS application stays focused on business logic while authorization policies evolve independently, managed by product or security teams without touching code.

How Cerbos works with Next.js

  1. Install the Cerbos SDK in your Next.js project. Add the JavaScript SDK as a dependency and configure a Cerbos client for use in your server-side code.
  2. Call Cerbos in middleware, server components, or API routes. Extract the authenticated user from your session or auth provider and call the Cerbos PDP to check whether the user can access the requested resource or perform the action.
  3. Define authorization policies in YAML. Write resource and principal policies that capture your access control rules, including roles, attributes, and conditions. Store them alongside your code and version them in git.
  4. Cerbos evaluates policies at request time. Every authorization check is evaluated against the latest policies with sub-millisecond latency. Update rules without redeploying your Next.js application.

FAQ

How do I integrate Cerbos with Next.js?

Install the Cerbos JavaScript SDK and call the Cerbos PDP from your Next.js middleware, server components, API routes, or server actions. Authorization runs server-side, so access decisions are enforced before data or pages reach the client.

Can I use Cerbos in Next.js middleware?

Yes. Next.js middleware runs before every matching request. You can call the Cerbos PDP to authorize the request and redirect or return a 403 before the page or API route is rendered. This is useful for blanket route protection.

Does Cerbos work with Next.js server components and server actions?

Yes. In server components, call Cerbos to gate data fetching and conditionally render content. In server actions, call Cerbos to authorize mutations before they execute. Both run exclusively on the server, so authorization decisions cannot be bypassed from the client.

Cerbos + NextJS

  • Single API call replaces hard-coded permission checks in NextJS
  • Policies updated independently of application deploys
  • Authorization policies versioned and tested like source code
  • Stateless PDP scales independently of the application

What is Cerbos?

Cerbos is an end-to-end enterprise authorization software for Zero Trust environments and AI-powered systems. It enforces fine-grained, contextual, and continuous authorization across apps, APIs, AI agents, MCP servers, services, and workloads.

Cerbos consists of an open-source Policy Decision Point, Enforcement Point integrations, and a centrally managed Policy Administration Plane (Cerbos Hub) that coordinates unified policy-based authorization across your architecture. Enforce least privilege & maintain full visibility into access decisions with Cerbos authorization.