---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://segmentstream.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# App SDK

Build signed-in Next.js pages that read and change workspace records as the current member.

## What you can build

- [Move an existing interface](https://segmentstream.com/docs/migrate-an-existing-app)

  Port a screen to the workspace app and test the same user task in preview.

- [Read records as a member](https://segmentstream.com/docs/sdk/app#show-the-current-member-s-leads)

  Use the typed client from a server component. The ontology checks each request.

- [Protect a page](https://segmentstream.com/docs/sdk/app#check-the-sign-in-and-permission-boundaries)

  Require sign-in at the route and test access with two roles.

## Connect the app to its workspace

Start in a linked workspace with the Next.js starter under app/. The CLI writes app/segmentstream.json. Import the ontology as a type so the app gets entity names and result types. The starter already mounts the SDK proxy and auth handlers.

app/src/segmentstream.ts

```
import { createSegmentStreamApp } from "@segmentstream/app";
import type ontology from "../../ontology";
import link from "../segmentstream.json";

export const segmentstream = createSegmentStreamApp<typeof ontology>(link);
```

## Show the current member’s leads

This server component uses the starter's Lead entity. The client uses the signed-in member's permissions. In a custom ontology, use the entity and property names from that workspace.

app/src/app/leads/page.tsx

```
import { segmentstream } from "@/segmentstream";

export default async function LeadsPage() {
  await segmentstream.requireUser();
  const { items } = await segmentstream.ontology.lead.find({ limit: 20 });
  return <ul>{items.map((lead) => <li key={lead.id}>{lead.email}</li>)}</ul>;
}
```

## Check the sign-in and permission boundaries

Deploy a preview and open /leads in a fresh browser session. A protected route takes the visitor to sign-in. A member with lead:read can load the list. Try a member whose roles lack that permission and confirm the server denies the read. Keep the route outside publicPaths.

## Selected API methods and types

### Create the typed client · `createSegmentStreamApp`

Creates the SegmentStream integration for a Next.js workspace app. Pass the type of the app's ontology to type \`segmentstream.ontology\`: \`\`\`ts import type ontology from "../../ontology"; import link from "../segmentstream.json"; export const segmentstream = createSegmentStreamApp\<typeof ontology>(link); \`\`\` With \`NEON_AUTH_BASE_URL\` set, users sign in with Neon Auth and their roles and permissions come from the ontology. Without it, members sign in with their SegmentStream account, as in 0.2.

```
function createSegmentStreamApp<O = unknown>(config: SegmentStreamAppConfig): SegmentStreamApp<O>;
```

### Render a sign-in form · `SignIn`

Email sign-in with Neon Auth in the SDK's neutral styles and the app's \`texts\`: \`useSignIn()\` with markup. Apps with their own design system render \`useSignIn()\` themselves.

```
function SignIn({ renderTelegram, renderBrowser, texts, ...options }: SignInProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;
```

### Show an allowed control · `Can`

Renders its children when the signed-in user holds the permission. It only hides controls: the ontology service checks every read and action itself.

```
function Can({ permission, children, fallback }: CanProps): ReactNode;
```

[Migrate an existing app](https://segmentstream.com/docs/migrate-an-existing-app)

[Read as Markdown ↗](https://segmentstream.com/docs/sdk/app.md)
