Next.js

Install Kilpi for Next


Install & setup Kilpi

Install Kilpi and setup your Kilpi instance by following the quickstart guide.

export const Kilpi = createKilpi({
getSubject,
policies,
...
})

Install React Server Components plugin

To automatically provide a scope for React Server Components, install the React Server Components Plugin.

Apply the plugin in your Kilpi configuration as follows.

kilpi.ts
export const Kilpi = createKilpi({
getSubject,
policies,
plugins: [ReactServerComponentPlugin()]
})

Read more about the plugin for more details on usage and available components.

Optional: Use Kilpi React Server Components

Use Kilpi to protect your UI in React Server Components with the components provided by the React Server Components plugin.

export const { Access } = Kilpi.ReactServer.createComponents();
<Access
to="documents:create"
Unauthorized={<p>Not authorized to create documents</p>}
>
<CreateDocumentForm />
</Access>

Read more about the Access component and other components provided by the plugin.

Provide scope for server actions and endpoints

To use the full feature set of Kilpi, you need to provide a scope for each request. The React Server Components can automatically only provide a scope for React Server Components.

Optional: Install Kilpi for React Client

To use Kilpi on the client and in client components, you must install and setup @kilpi/client and @kilpi/react-client for client-side bindings.