Server client
Send the customer domain and required DNS records from your trusted server.
Use createDomain0PlatformClient() in your backend to create the DNS intent
that Domain0 Connect will show to your customer.
import { createDomain0PlatformClient } from 'domain0'
const platform = createDomain0PlatformClient({
baseUrl: 'https://domain0.dev/api/domain0/',
apiKey: process.env.DOMAIN0_API_KEY!,
})Server only
Never construct this client in a Client Component, browser bundle, mobile webview, or public edge response. A Domain0 API key is long-lived authority for its bound application.
Create a connection
const { connection } = await platform.createConnection({
intent: {
domain: 'customer.example',
records: [
{
host: 'app',
type: 'CNAME',
value: 'edge.your-product.com',
ttl: 300,
},
],
},
})The records array is the source of truth for the customer flow. Build it from
your product configuration or trusted application data, not arbitrary browser
input.
Issue browser access
const access = await platform.issueConnectionToken(connection.id, {
origin: 'https://app.your-product.com',
})The returned bearer token expires quickly and is restricted to the exact connection and origin. Return it only to the browser session that will open the flow.
Refresh safely
If the dialog remains open near token expiry, ask your server for another token for the same connection. Pass an async token resolver to the browser client so concurrent requests share your refresh promise.