Installation
Install Own Auth, configure Postgres, and create the required database tables.
Requirements
- Node.js 20 or later, or a Cloudflare Worker with
nodejs_compat - A Postgres database, or Cloudflare D1 when deploying to Workers
Cloudflare Workers use the explicit own-auth/d1 adapter without loading the Node.js pg driver. See Cloudflare D1 for the complete Worker setup.
Install the package
npm install own-authOr with another package manager:
pnpm add own-auth
yarn add own-authSet up your environment
The default Postgres setup reads two environment variables:
# .env
DATABASE_URL=postgres://user:password@localhost:5432/myapp
OWN_AUTH_TOKEN_PEPPER=your-random-secret-stringDATABASE_URL is your Postgres connection string. Any Postgres provider works: local, Supabase, Neon, Railway, RDS, or a VPS running Postgres.
Cloudflare D1 uses a Worker binding instead of DATABASE_URL. The token pepper remains a server-only Worker secret.
OWN_AUTH_TOKEN_PEPPER adds an extra layer of protection when hashing tokens. Generate a long random string, keep it secret, and use it only on the backend. If you change it, existing sessions, auth links, SMS codes, and API keys become invalid.
To generate a pepper:
openssl rand -base64 32Run migrations
For Postgres:
npx own-auth migrateThis creates the tables Own Auth needs in your database:
own_auth_migrationsown_auth_usersown_auth_accountsown_auth_sessionsown_auth_tokensown_auth_sms_otpsown_auth_organisationsown_auth_organisation_membersown_auth_invitationsown_auth_api_keysown_auth_audit_eventsown_auth_rate_limitsown_auth_oauth_transactionsown_auth_mfa_factorsown_auth_recovery_codesown_auth_mfa_challengesown_auth_oauth_credentialsown_auth_passkeysown_auth_webauthn_challengesown_auth_plugin_migrationsown_auth_webhook_eventsown_auth_webhook_deliveriesown_auth_webhook_attemptsown_auth_authorization_clientsown_auth_authorization_client_secretsown_auth_authorization_interactionsown_auth_authorization_grantsown_auth_authorization_codesown_auth_authorization_access_tokensown_auth_authorization_refresh_tokensown_auth_oidc_subjectsown_auth_protected_resourcesown_auth_protected_resource_secretsown_auth_dpop_proofsown_auth_saml_connectionsown_auth_saml_transactionsown_auth_saml_assertion_replaysown_auth_scim_connectionsown_auth_scim_tokensown_auth_scim_users
All Own Auth tables are prefixed with own_auth_ to avoid conflicts. Your existing application tables are not modified.
For Cloudflare D1, generate versioned files and apply them with Wrangler. See Cloudflare D1.
Verify
Check that everything is connected:
npx own-auth statusThis prints the database connection status and the latest applied migration version. If it shows Database: connected and Status: current, you are ready.
Database providers
Own Auth works with any Postgres database. Some common setups:
Local Postgres
DATABASE_URL=postgres://postgres:postgres@localhost:5432/myappSupabase
DATABASE_URL=postgres://postgres:[password]@db.[project].supabase.co:5432/postgresNeon
DATABASE_URL=postgres://[user]:[password]@[endpoint].neon.tech/[database]?sslmode=requireRailway
DATABASE_URL=${{Postgres.DATABASE_URL}}AWS RDS
DATABASE_URL=postgres://[user]:[password]@[instance].rds.amazonaws.com:5432/[database]?sslmode=requireUse ?sslmode=require for hosted databases that require TLS.
Next step
Create your auth instance in the Configuration guide.