setup-flows-auth
cognitedata/builder-skills
Wire a React app for Flows authentication to connect to CDF inside Fusion.
What is setup-flows-auth?
Sets up authentication for React apps migrating to Flows or lacking auth configuration. Detects whether to use the classic DuneAuthProvider flow or the newer Apps API flow based on app.json, installs required dependencies, configures Vite, and wires up the entry file. No-op if valid auth is already in place.
- Detects classic vs Apps API authentication flow from app.json infra field
- Installs required packages (dune, app-sdk, react-query, vite-plugin-mkcert) based on flow type
- Configures Vite with fusionOpenPlugin, manifestCspPlugin, and mkcert for HTTPS dev server
- Wraps React entry point with appropriate auth provider (DuneAuthProvider or CogniteSdkProvider)
- Removes superseded custom auth code and CDF environment variables
How to install setup-flows-auth
npx skills add https://github.com/cognitedata/builder-skills --skill setup-flows-auth- Existing React app with package.json and src/main.tsx (or src/index.tsx)
- Node.js and a package manager (npm, yarn, or pnpm)
- app.json file (optional; defaults to Apps API flow if missing)
How to use setup-flows-auth
- 1.Read app.json to determine flow type (Apps API if infra is 'appsApi', otherwise Classic)
- 2.Check package.json and entry file to confirm no valid auth setup already exists
- 3.Install missing dependencies using detected package manager
- 4.Update vite.config.ts with required plugins (fusionOpenPlugin, manifestCspPlugin for Apps API, mkcert)
- 5.Replace entry file (main.tsx) with appropriate auth provider wrapper
- 6.Update App.tsx to use CogniteSdkProvider (Apps API) or useDune hook (Classic)
- 7.Remove any custom CDF auth providers, manual CogniteClient instantiation, and CDF environment variables
Use cases
- Migrating an existing React app to run inside Fusion as a Flow
- Adding authentication to a new React app that will run in Fusion
- Setting up CDF client access for components that need to query Cognite Data Fusion
- Configuring HTTPS dev server with automatic Fusion iframe integration
- Switching from manual CogniteClient instantiation to provider-based auth
- React developers building Fusion apps
- Teams migrating legacy React apps to Flows
- Developers setting up new Cognite Data Fusion integrations
- Frontend engineers working in Fusion iframe environments
setup-flows-auth FAQ
Check your app.json infra field. If it says 'appsApi', use the Apps API flow with CogniteSdkProvider. If missing or set to something else, use the Classic flow with DuneAuthProvider. Default to Apps API if no app.json exists.
The skill detects valid existing setups and does nothing (no-op). It checks for DuneAuthProvider wrapping App in Classic flow, or CogniteSdkProvider in App.tsx for Apps API flow.
No. Flows and the Fusion host provide project and cluster information automatically. Remove any VITE_CDF_PROJECT, VITE_CDF_CLUSTER, or similar env vars.
The Fusion parent frame uses HTTPS, so your dev server must also use HTTPS. mkcert provides self-signed certificates for local development.
No. Pick one based on your app.json infra field. They are mutually exclusive authentication patterns.
Full instructions (SKILL.md)
Source of truth, from cognitedata/builder-skills.
name: setup-flows-auth
description: "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."
allowed-tools: Read, Glob, Grep, Edit, Write, Bash
metadata:
argument-hint: ""
Set Up Flows Authentication
Wire a React app for Flows auth so it can talk to CDF inside Fusion. Two flows exist; pick one based on app.json.
Pick the flow
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.
Step 1 — Read state, decide whether to act
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:
- Classic:
<DuneAuthProvider>from@cognite/dunewraps<App />in the entry file. - Apps API, provider pattern:
<CogniteSdkProvider>from@cognite/app-sdk/reactwraps the app (inApp.tsxormain.tsx), and nested components consume the client viauseCogniteSdk(). Requires@cognite/app-sdk >= 0.5.1.
Detect the package manager from the lock file (pnpm-lock.yaml → pnpm, yarn.lock → yarn, otherwise npm).
Step 2 — Install missing deps
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).
Step 3 — Vite config
Add only what's missing. Don't remove existing plugins.
Classic flow
import { fusionOpenPlugin } from "@cognite/dune/vite";
import mkcert from "vite-plugin-mkcert";
export default defineConfig({
base: "./",
plugins: [react(), mkcert(), fusionOpenPlugin(), /* ... */],
server: { port: 3001 },
worker: { format: "es" },
});
Apps API flow
// or see @cognite/cli/_templates/app/new/config/vite.config.ts.ejs.t source file for newest config
import { fusionOpenPlugin, manifestCspPlugin } from "@cognite/app-sdk/vite";
import mkcert from "vite-plugin-mkcert";
export default defineConfig({
base: "./",
// manifestCspPlugin() must be first — its middleware sets the CSP header before any HTML response
plugins: [manifestCspPlugin(), react(), mkcert(), fusionOpenPlugin(), /* ... */],
server: { port: 3001 },
worker: { format: "es" },
});
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 inmanifest.json; must be first.server.port: 3001— convention; the plugin falls back to 3001 if no port is set.
Step 4 — Wire up the entry file and component
Classic flow
src/main.tsx:
import { DuneAuthProvider } from "@cognite/dune";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 5 * 60 * 1000, gcTime: 10 * 60 * 1000 } },
});
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<DuneAuthProvider>
<App />
</DuneAuthProvider>
</QueryClientProvider>
</React.StrictMode>
);
In components, use useDune():
import { useDune } from "@cognite/dune";
const { sdk, isLoading, error } = useDune();
// sdk is an authenticated CogniteClient
Apps API flow (generator default, @cognite/app-sdk >= 0.5.1)
src/main.tsx does not wrap in any auth provider — auth is handled inside App.tsx:
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 5 * 60 * 1000, gcTime: 10 * 60 * 1000 } },
});
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</React.StrictMode>
);
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():
import { CogniteSdkProvider, useCogniteSdk } from "@cognite/app-sdk/react";
function AppContent() {
const client = useCogniteSdk();
// client is an authenticated CogniteClient
return <div>{client.project}</div>;
}
function App() {
return (
<CogniteSdkProvider
loadingFallback={<div>Loading...</div>}
errorFallback={<div>Failed to connect to Fusion</div>}
>
<AppContent />
</CogniteSdkProvider>
);
}
useCogniteSdk() throws if called outside CogniteSdkProvider — always nest it inside.
Step 5 — Clean up superseded code
Remove only what's now redundant:
- Custom CDF auth providers/hooks
- Manual
CogniteClientinstantiation - OIDC/token-management code
- CDF env vars (
VITE_CDF_PROJECT,VITE_CDF_CLUSTER, etc.) — Flows/the host provide these
If unsure, leave it and flag to the user.
Related skills
More from cognitedata/builder-skills and the wider catalog.

setup-python-tools
Add client-side Python tool execution via Pyodide to Flows apps with automatic hook setup and chat integration.

skill-creator
Create, improve, and evaluate AI agent skills with iterative testing and performance benchmarking.

test-coverage
Find and fix test coverage gaps to meet the 80% line coverage hard gate for Flows apps.

use-topbar
Wire Aura Topbar into Flows/Fusion apps as the compliant single top navigation bar with breadcrumbs, theme switching, and utility strip.

agentic-wallet
Crypto wallet operations via the awal CLI — sign in, check balances, send USDC/ETH/POL/SOL, trade tokens, fund the wallet, and use the x402 payment protocol to discover paid services, pay for API calls, monetize an API, or query onchain data. Use whenever the user mentions signing in, login, authentication, wallet status, balance, address, sending money, paying someone, transferring tokens, ENS names, swapping/trading/converting tokens, funding/topping up/onramp, USDC, ETH, POL, SOL, the x402 bazaar, paid APIs, monetizing an endpoint, or querying onchain data on Base.

authenticate-wallet
Sign in to your wallet via email OTP before sending, trading, or funding.