insforge-integrations
insforge/insforge-skills
Wire external auth providers and x402 payment facilitators into InsForge for JWT-based RLS and onchain billing.
What is insforge-integrations?
Integrates third-party authentication providers (Clerk, Auth0, WorkOS, Kinde, Stytch, Better Auth) and payment facilitators (OKX x402) with InsForge. Use this when you need to add user authentication with row-level security via JWT claims or implement pay-per-use billing settled onchain.
- Connect Clerk, Auth0, WorkOS, Kinde, Stytch, or Better Auth for JWT-based row-level security
- Embed user claims into JWT tokens for InsForge RLS policies
- Integrate OKX x402 payment facilitator for onchain pay-per-use HTTP endpoints
- Implement EIP-3009 authorization signing for stablecoin payments
- Set up realtime payment dashboards with database triggers
- Support both SaaS and self-hosted auth options
How to install insforge-integrations
npx skills add https://github.com/insforge/insforge-skills --skill insforge-integrations- InsForge project with Postgres database
- npx @insforge/cli installed for secrets management
- JWT_SECRET available via `npx -y @insforge/cli secrets get JWT_SECRET`
- For auth: credentials from your chosen provider (Clerk, Auth0, WorkOS, Kinde, Stytch, or Better Auth)
- For x402: OKX Web3 API key (not exchange trading API) and USDG token contract details
How to use insforge-integrations
- 1.Identify which auth provider or payment facilitator your project uses
- 2.Read the corresponding reference guide (e.g., references/clerk.md, references/okx-x402.md)
- 3.Configure the provider in their dashboard (API keys, JWT templates, application settings)
- 4.Implement server-side code: JWT utilities for auth, or facilitator client + EIP-712 signing for payments
- 5.Create the `requesting_user_id()` function in your database for RLS policies
- 6.Set up RLS policies using JWT claims via `auth.jwt()`
- 7.For payments: create payment table with UNIQUE tx_hash constraint and realtime trigger
- 8.Add environment variables for provider credentials and JWT_SECRET
Use cases
- Adding Clerk authentication with zero server-side JWT signing via JWT Templates
- Implementing Auth0 post-login Actions to inject custom claims for RLS
- Setting up WorkOS AuthKit with server-side JWT signing for enterprise SSO
- Configuring pay-per-use API endpoints with OKX x402 and USDG stablecoin settlement
- Building multi-tenant applications with JWT-based row-level security
- Backend developers integrating third-party auth into InsForge applications
- Teams implementing row-level security with external identity providers
- Projects requiring onchain pay-per-use billing via x402 HTTP payment protocol
- Developers building multi-tenant SaaS platforms with JWT claims
- Teams choosing between SaaS auth providers and self-hosted Better Auth
insforge-integrations FAQ
Clerk is simplest (JWT Template, no server signing); Auth0 is flexible (post-login Actions); WorkOS is enterprise-focused (AuthKit + server signing); Kinde is developer-friendly; Stytch is API-first; Better Auth is self-hosted in your Postgres with no SaaS vendor or per-MAU cost.
Third-party provider user IDs are strings, not UUIDs. The `requesting_user_id()` function extracts the user ID from JWT claims and must be used in RLS policies.
Pass it via the `accessToken` parameter in `createClient()`. For short-lived tokens (like Clerk), sync refreshes with `client.setAccessToken(token, AuthChangeEvent.TOKEN_REFRESHED)` after sign-in.
Always check the `{ error }` result after `insert()`. Settlement moves money onchain before the database insert runs, so a silent DB failure loses the payment record. Log and handle all errors.
No. Create a separate Web3 API key at web3.okx.com/onchainos/dev-portal. Exchange trading keys will not work with the x402 payment facilitator.
Full instructions (SKILL.md)
Source of truth, from insforge/insforge-skills.
name: insforge-integrations description: >- Use when wiring an external auth provider (Clerk, Auth0, WorkOS, Kinde, Stytch, Better Auth) into InsForge for JWT-based RLS, or when adding the OKX x402 payment facilitator for onchain pay-per-use billing. license: Apache-2.0
InsForge Integrations
This skill covers integrating third-party providers with InsForge. Currently two categories are supported: auth providers (RLS via JWT claims) and payment facilitators (x402 HTTP payment protocol). Each provider has its own guide under this directory.
Auth Providers
| Provider | Guide | When to use |
|---|---|---|
| Clerk | Clerk JWT Templates + InsForge RLS | Clerk signs tokens directly via JWT Template — no server-side signing needed |
| Auth0 | Auth0 Actions + InsForge RLS | Auth0 uses a post-login Action to embed claims into the access token |
| WorkOS | WorkOS AuthKit + InsForge RLS | WorkOS AuthKit middleware + server-side JWT signing with jsonwebtoken |
| Kinde | Kinde + InsForge RLS | Kinde token customization for InsForge integration |
| Stytch | Stytch + InsForge RLS | Stytch session tokens for InsForge integration |
| Better Auth | Better Auth + InsForge RLS | Self-hosted auth running in your InsForge Postgres — no third-party SaaS, no per-MAU cost |
Payment Facilitators
| Provider | Guide | When to use |
|---|---|---|
| OKX x402 | OKX as x402 facilitator (USDG on X Layer) | Pay-per-use HTTP endpoints settled onchain with zero gas for the payer |
Common Patterns
Auth providers
- Provider signs or issues a JWT containing the user's ID
- JWT is passed to InsForge via
accessTokenincreateClient()(deprecated alias:edgeFunctionToken) - InsForge exposes claims through
auth.jwt()in SQL - RLS policies use a
requesting_user_id()function to enforce row-level security
Payment facilitators (x402)
- Server returns
402 Payment Requiredwith a JSON challenge base64-encoded inPAYMENT-REQUIREDheader - Client signs an EIP-3009 authorization using the stablecoin's EIP-712 domain
- Server forwards the signed payload to the facilitator's
/verify+/settleendpoints - Server records the settled payment in an InsForge table with a realtime trigger for live dashboards
Choosing a Provider
Auth
- Clerk — Simplest setup; JWT Template handles signing, no server code needed
- Auth0 — Flexible; uses post-login Actions for claim injection
- WorkOS — Enterprise-focused; AuthKit middleware + server-side JWT signing
- Kinde — Developer-friendly; built-in token customization
- Stytch — API-first; session-based token flow
- Better Auth — Self-hosted in your Postgres; no SaaS vendor; you own the user table. Pairs cleanly with InsForge's Postgres via a connection string + a small bridge route. Requires a one-time
REVOKEafter migrate to seal PostgREST exposure.
Payment facilitators
- OKX x402 — Onchain pay-per-use via USDG on X Layer; zero gas for the payer
Setup
- Identify which provider the project uses
- Read the corresponding reference guide from the tables above
- Follow the provider-specific setup steps
Usage Examples
Each provider guide includes full code examples for:
- Provider dashboard configuration (API keys, application settings, etc.)
- Server and client code (JWT utilities for auth; facilitator client + signing utilities for payments)
- Database setup (RLS for auth; payment table + realtime trigger for payments)
- Environment variable setup
Refer to the specific references/<provider>.md file for complete examples.
Best Practices
Auth
- All auth provider user IDs are strings (not UUIDs) — always use
TEXTcolumns foruser_id - Use
requesting_user_id()instead ofauth.uid()for RLS policies - Pass the JWT via
accessToken— a static string, not a function; for short-lived tokens (Clerk) sync refreshes withclient.setAccessToken(token, AuthChangeEvent.TOKEN_REFRESHED)after the initial same-user sign-in - Always get the JWT secret via
npx -y @insforge/cli secrets get JWT_SECRET
Payment facilitators (x402)
- Always check the result of the database
insert(...)after settlement — settlement takes money onchain before the insert runs; a silent DB failure loses the record - Add
UNIQUEto thetx_hashcolumn to prevent duplicate records from retries - Verify EIP-712 domain (
name,version) against the token contract's on-chainDOMAIN_SEPARATOR— wrong values produceInvalid Authorityerrors - Use a
MOCK_OKX_FACILITATORenv flag for local dev so the full flow can be exercised without real funds
Common Mistakes
Auth
| Mistake | Solution |
|---|---|
Using auth.uid() for RLS | Use requesting_user_id() — third-party IDs are strings, not UUIDs |
Using UUID columns for user_id | Use TEXT — all supported providers use string-format IDs |
| Hardcoding the JWT secret | Always retrieve via npx -y @insforge/cli secrets get JWT_SECRET |
Missing requesting_user_id() function | Must be created before RLS policies will work |
Payments (x402)
| Mistake | Solution |
|---|---|
| Using an OKX exchange trading API key | Create a separate Web3 API key at web3.okx.com/onchainos/dev-portal |
| Wrong EIP-712 domain values | Read the token contract's DOMAIN_SEPARATOR — for USDG on X Layer use name: "Global Dollar", version: "1" |
| Ignoring DB insert error after settlement | Always destructure { error } and log/handle it — money has already moved |
MOCK_OKX_FACILITATOR=true in production | Mock mode is demo-only; it returns fake tx hashes and bypasses verification |
Related skills
More from insforge/insforge-skills and the wider catalog.

insforge
SDK integration for InsForge app backends: database, auth, storage, functions, AI, realtime, email, and payments.

insforge-cli
Manage InsForge backend and cloud infrastructure via CLI for projects, databases, deployments, and integrations.

insforge-debug
Diagnose InsForge project failures using logs, metrics, DB health, policies, and AI-assisted triage.

insta
Operate InstaCloud infrastructure: deploy apps, manage databases, storage, compute, and branch environments via CLI.

instantdb
Build complete, functional apps with InstantDB as the backend for React, vanilla JS, and Expo.

anki-connect
This skill is for interacting with Anki through AnkiConnect, and should be used whenever a user asks to interact with Anki, including to read or modify decks, notes, cards, models, media, or sync operations.