Authentication
NextGenKit's auth system is built on Clerk v7 with full organization support.
Auth Guards
Use these helpers in server actions and route handlers:
import { requireUser, requireOrg, requireRole } from "@/lib/auth"
// Require any authenticated user
const user = await requireUser()
// Require user to be in an organization
const org = await requireOrg()
// Require specific role within the org
await requireRole("admin")
Protected Routes
The middleware in proxy.ts handles route protection. Public routes are explicitly listed — everything else requires authentication.
Organization Switching
Users can belong to multiple organizations. The active org is managed by Clerk and accessible via:
import { auth } from "@clerk/nextjs/server"
const { orgId, orgSlug } = await auth()
Webhooks
Clerk webhooks sync user/org data to your database. The handler at app/api/webhooks/clerk/route.ts processes:
user.created— Creates user record in DBuser.updated— Syncs profile changesorganization.created— Creates org recordorganizationMembership.created— Links user to org