Skip to main content

Overview

WorkOS is an enterprise authentication platform that provides AuthKit (hosted login UI), Single Sign-On (SSO), SCIM directory sync, and user management. This guide shows how to integrate WorkOS with InsForge in a Next.js application. WorkOS handles authentication and enterprise identity, while InsForge manages data authorization through Row Level Security (RLS) policies.
  • Live Demo — A sample app using WorkOS authentication with InsForge
  • Source Code — GitHub repository for the sample app

Prerequisites

  • An InsForge project (self-hosted or cloud)
  • A WorkOS account

Step 1: Create a WorkOS Application

  1. Log in to your WorkOS Dashboard
  2. Go to API Keys and note down the API Key and Client ID
  3. Navigate to Redirects and add http://localhost:3000/callback
  4. Enable your desired authentication methods (email/password, social login, SSO, etc.)

Step 2: Set Up Your InsForge Project

Create a new project or link an existing one:
Then get your project credentials:
Note down the URL and Anon Key from the InsForge dashboard.

Step 3: Set Up Your Application

Install the required dependencies:
Add environment variables to .env.local:

Step 4: Set Up InsForge Integration

Ask your agent to complete the following steps:

1. Set up WorkOS AuthKit and InsForge integration

This creates the callback route (app/callback/route.ts), AuthKitProvider wrapper (app/layout.tsx), middleware (middleware.ts), and login route (app/login/route.ts).

2. Create the InsForge client utility

This creates a server-side utility (lib/insforge.ts) that gets the WorkOS user via withAuth(), signs a JWT with the InsForge secret, and passes it as edgeFunctionToken.

3. Create the database schema

This creates the requesting_user_id() helper function (since WorkOS user IDs are strings, not UUIDs) and a todos table with Row Level Security policies.

4. Build the todo list page

This creates a page that uses the InsForge client to manage todos. RLS ensures users only see their own data.

Step 5: Run Your Application

Open http://localhost:3000 and sign up with a new user through WorkOS.
Since authentication is handled entirely by WorkOS, you will not see any users in the InsForge dashboard under Auth > Users. User records are managed in the WorkOS Dashboard — check Users there to confirm the sign-up was successful.
InsForge Auth Users — empty because WorkOS manages users