Skip to contentSkip to navigation

Setup

Connect the Own Auth package to Cloud with one app key.

1. Install Own Auth

Install own-auth and connect it to Postgres. Cloudflare Workers can use Cloudflare D1 instead. For Postgres, create the required database tables before starting the app. Cloud uses the package's local outbox and never connects to the application database.

bash
npm install own-auth
npx own-auth migrate

2. Create an app and key

Create a Cloud account, add an app, then create its Cloud API key from API Keys. The raw key is shown once.

.env
OWN_AUTH_CLOUD_KEY=oac_sk_...

3. Add Cloud

Add cloud() to the same Own Auth instance. Request mode is the safe default for serverless runtimes because the outbox is flushed before the operation finishes.

auth.ts
import { createOwnAuth } from "own-auth";
import { cloud } from "own-auth/cloud";

export const auth = createOwnAuth({
  tokenPepper: process.env.OWN_AUTH_TOKEN_PEPPER,
  plugins: [cloud({ key: process.env.OWN_AUTH_CLOUD_KEY! })]
});

4. Backfill existing data

For an existing application, run auth.cloud.backfill() once. It copies current users, organisations, active memberships, and active sessions. It is resumable and sends at most 500 records per second.

ts
await auth.cloud.backfill();