insforge-integrations

作者: insforge

用于在将外部认证提供商(Clerk、Auth0、WorkOS、Kinde、Stytch、Better Auth)接入InsForge以实现基于JWT的RLS时,或添加OKX x402支付协调器以进行链上按使用量付费计费时。

npx skills add https://github.com/insforge/insforge-skills --skill insforge-integrations

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

ProviderGuideWhen to use
ClerkClerk JWT Templates + InsForge RLSClerk signs tokens directly via JWT Template — no server-side signing needed
Auth0Auth0 Actions + InsForge RLSAuth0 uses a post-login Action to embed claims into the access token
WorkOSWorkOS AuthKit + InsForge RLSWorkOS AuthKit middleware + server-side JWT signing with jsonwebtoken
KindeKinde + InsForge RLSKinde token customization for InsForge integration
StytchStytch + InsForge RLSStytch session tokens for InsForge integration
Better AuthBetter Auth + InsForge RLSSelf-hosted auth running in your InsForge Postgres — no third-party SaaS, no per-MAU cost

Payment Facilitators

ProviderGuideWhen to use
OKX x402OKX as x402 facilitator (USDG on X Layer)Pay-per-use HTTP endpoints settled onchain with zero gas for the payer

Common Patterns

Auth providers

  1. Provider signs or issues a JWT containing the user's ID
  2. JWT is passed to InsForge via accessToken in createClient() (deprecated alias: edgeFunctionToken)
  3. InsForge exposes claims through auth.jwt() in SQL
  4. RLS policies use a requesting_user_id() function to enforce row-level security

Payment facilitators (x402)

  1. Server returns 402 Payment Required with a JSON challenge base64-encoded in PAYMENT-REQUIRED header
  2. Client signs an EIP-3009 authorization using the stablecoin's EIP-712 domain
  3. Server forwards the signed payload to the facilitator's /verify + /settle endpoints
  4. 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 REVOKE after migrate to seal PostgREST exposure.

Payment facilitators

  • OKX x402 — Onchain pay-per-use via USDG on X Layer; zero gas for the payer

Setup

  1. Identify which provider the project uses
  2. Read the corresponding reference guide from the tables above
  3. 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 TEXT columns for user_id
  • Use requesting_user_id() instead of auth.uid() for RLS policies
  • Pass the JWT via accessToken — a static string, not a function; for short-lived tokens (Clerk) sync refreshes with client.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 UNIQUE to the tx_hash column to prevent duplicate records from retries
  • Verify EIP-712 domain (name, version) against the token contract's on-chain DOMAIN_SEPARATOR — wrong values produce Invalid Authority errors
  • Use a MOCK_OKX_FACILITATOR env flag for local dev so the full flow can be exercised without real funds

Common Mistakes

Auth

MistakeSolution
Using auth.uid() for RLSUse requesting_user_id() — third-party IDs are strings, not UUIDs
Using UUID columns for user_idUse TEXT — all supported providers use string-format IDs
Hardcoding the JWT secretAlways retrieve via npx -y @insforge/cli secrets get JWT_SECRET
Missing requesting_user_id() functionMust be created before RLS policies will work

Payments (x402)

MistakeSolution
Using an OKX exchange trading API keyCreate a separate Web3 API key at web3.okx.com/onchainos/dev-portal
Wrong EIP-712 domain valuesRead the token contract's DOMAIN_SEPARATOR — for USDG on X Layer use name: "Global Dollar", version: "1"
Ignoring DB insert error after settlementAlways destructure { error } and log/handle it — money has already moved
MOCK_OKX_FACILITATOR=true in productionMock mode is demo-only; it returns fake tx hashes and bypasses verification

来自 insforge 的更多技能

insforge-debug
insforge
在诊断InsForge项目问题时使用——包括被动故障(SDK错误对象、HTTP 4xx/5xx、网关超时502/503/504、边缘函数故障或超时、登录/OAuth/认证错误、RLS拒绝、实时频道问题、单个端点查询缓慢、边缘函数或Vercel部署失败)、主动审计(安全/RLS审查、性能/索引审查、系统健康检查、上线前准备),或用户遇到错误但不知从何入手时。
insforge
insforge
在编写使用 InsForge 或 @insforge/sdk 的应用代码时使用此技能:数据库 CRUD、认证、存储上传/存储 RLS、函数、OpenRouter AI、实时功能、电子邮件、Stripe 或 Razorpay 支付,或将兼容 S3 的工具(aws CLI、AWS SDK、rclone、Terraform、boto3)指向 InsForge 存储。在遇到添加认证、获取数据、上传文件、公开存储桶、添加结账、销售订阅或发送电子邮件等请求时触发。适用于基础设施、SQL 迁移、CLI 命令或支付提供商...
developmentdatabaseaws
insforge-cli
insforge
当有人需要后端,或任务涉及通过InsForge CLI操作InsForge后端或云基础设施时,使用此技能:项目、SQL、迁移、RLS策略、函数、存储、部署、计算、密钥、配置、调度、日志、诊断、导入/导出、AI/OpenRouter设置、Stripe/Razorpay支付、Apify网页抓取/数据源、PostHog产品分析、后端分支、代理记忆(记住/回忆项目事实和决策)或CLI文档。对于应用代码...
developmentdatabasedevops
insforge-integrations
insforge
在将外部认证提供商(Clerk、Auth0、WorkOS、Kinde、Stytch、Better Auth)接入InsForge以实现基于JWT的行级安全(RLS),或添加OKX x402支付协调器以进行链上按使用付费计费时使用。
insforge-debug
insforge
用于诊断InsForge项目中的问题——响应式故障(SDK错误对象、HTTP 4xx/5xx、网关超时502/503/504、边缘函数故障或超时、登录/OAuth/认证错误、RLS拒绝、实时通道问题、单端点慢查询、边缘函数或Vercel部署失败)、主动审计(安全/RLS审查、性能/索引审查、系统健康检查、上线前就绪检查),或者当用户遇到错误但不知道从何入手时。
insforge-cli
insforge
每当有人需要后端,或任务涉及通过InsForge CLI操作InsForge后端或云基础设施时,使用此技能:项目、SQL、迁移、RLS策略、函数、存储、备份、部署、计算、密钥、配置、调度、日志、诊断、顾问扫描和抑制、导入/导出、AI/OpenRouter设置与使用概览、Stripe/Razorpay支付、Apify网络抓取/数据源、PostHog产品分析、后端分支、组织成员资格……
insforge
insforge
在编写InsForge或@insforge/sdk的应用代码时使用此技能,涉及:数据库CRUD、认证、存储上传/存储RLS、函数、OpenRouter AI、实时功能、电子邮件、Stripe或Razorpay支付,或将S3兼容工具(aws CLI、AWS SDKs、rclone、Terraform、boto3)指向InsForge Storage。在遇到以下请求时触发:添加认证、获取数据、上传文件、设置存储桶公开、添加结账、销售订阅或发送电子邮件。针对基础设施、SQL迁移、CLI命令或支付提供商...