Framework

Seed Next.js + Clerk User Data with MockHero

The Setup

Clerk handles auth. Your app has a profiles table keyed by Clerk's user_id. After creating test Clerk users programmatically, seed matching profile rows from MockHero.

// scripts/seed-profiles.ts
import { clerkClient } from "@clerk/nextjs/server";
import { db } from "@/db";
import { profiles } from "@/db/schema";

// 1. Get Clerk user IDs
const { data: users } = await clerkClient.users.getUserList({ limit: 50 });
const clerkIds = users.map(u => u.id);

// 2. Generate matching profile content
const res = await fetch("https://api.mockhero.dev/api/v1/generate", {
  method: "POST",
  headers: { "x-api-key": process.env.MOCKHERO_API_KEY!, "Content-Type": "application/json" },
  body: JSON.stringify({
    tables: [{
      name: "profiles", count: clerkIds.length, fields: [
        { name: "bio", type: "paragraph" },
        { name: "website", type: "url" },
        { name: "location", type: "city" }
      ]
    }]
  })
}).then(r => r.json());

// 3. Pair them
await db.insert(profiles).values(
  res.profiles.map((p: any, i: number) => ({ user_id: clerkIds[i], ...p }))
);

Get Started

Free API key.

M

MockHero Team

Guides and tutorials for generating realistic test data with the MockHero API.

Start generating test data for free

1,000 rows/month on the free tier. No credit card required.

Get Your API Key

Related Articles