npx skills add ...
npx skills add cognitedata/builder-skills --skill setup-flows-auth
MUST be used when migrating an existing React app to Flows, or when no Flows auth is wired up. Detects classic vs Apps API flow from `app.json` `infra` field, installs the right packages, and wires up the entry file. No-op when a valid auth setup is already in place. Triggers: migrate to Flows, add Flows auth, DuneAuthProvider, AppSdkAuthProvider, connectToHostApp, useDune, Flows setup, setup auth, missing auth provider, CDF authentication, Fusion iframe auth.
npx skills add cognitedata/builder-skills --skill setup-flows-auth
Wire a React app for Flows auth so it can talk to CDF inside Fusion. Two flows exist; pick one based on app.json.
Read app.json if present:
app.json infra | Flow | Auth source | Extra package |
|---|---|---|---|
"appsApi" | Apps API (new Fusion app host) | connectToHostApp from @cognite/app-sdk | @cognite/app-sdk |
| missing / other | Classic (legacy Files API) | DuneAuthProvider + useDune() from @cognite/dune | — |
No app.json? Ask the user. Default to Apps API — it's the default for npx @cognite/cli@latest apps create.
Read package.json, src/main.tsx (or src/index.tsx), vite.config.ts, app.json.
A valid setup already exists if any of these is true — in which case do nothing and report no-op:
<DuneAuthProvider> from @cognite/dune wraps <App /> in the entry file.<CogniteSdkProvider> from @cognite/app-sdk/react wraps the app (in App.tsx or main.tsx), and nested components consume the client via useCogniteSdk(). Requires @cognite/app-sdk >= 0.5.1.Detect the package manager from the lock file (pnpm-lock.yaml → pnpm, yarn.lock → yarn, otherwise npm).
Classic flow:
| Package | Type |
|---|---|
@cognite/dune | runtime |
@cognite/sdk | runtime |
@tanstack/react-query | runtime |
vite-plugin-mkcert | dev |
Apps API flow:
| Package | Type |
|---|---|
@cognite/app-sdk | runtime |
@cognite/sdk | runtime |
@tanstack/react-query | runtime |
vite-plugin-mkcert | dev |
Skip anything already in package.json. Use the detected package manager (pnpm add, npm install, yarn add; -D / --save-dev for dev deps).
Add only what's missing. Don't remove existing plugins.
base: "./" — required for Fusion iframe deployment.mkcert() — provides HTTPS for the dev server (the Fusion parent is HTTPS).fusionOpenPlugin() — opens the dev URL inside Fusion automatically.manifestCspPlugin() (Apps API only) — enforces the CSP declared in manifest.json; must be first.server.port: 3001 — convention; the plugin falls back to 3001 if no port is set.src/main.tsx:
In components, use useDune():
@cognite/app-sdk >= 0.5.1)src/main.tsx does not wrap in any auth provider — auth is handled inside App.tsx:
src/App.tsx uses CogniteSdkProvider from @cognite/app-sdk/react. The provider handles the Comlink handshake, loading, and error states internally. Nested components read the client via useCogniteSdk():
useCogniteSdk() throws if called outside CogniteSdkProvider — always nest it inside.
Remove only what's now redundant:
CogniteClient instantiationVITE_CDF_PROJECT, VITE_CDF_CLUSTER, etc.) — Flows/the host provide theseIf unsure, leave it and flag to the user.