Skip to content

WorkOS AuthKit

Use WorkOS AuthKit when you standardize on @workos-inc/authkit-nextjs for enterprise SSO and want ownerId from the authenticated WorkOS user record.

  1. Copy examples/with-workos/.env.example and configure:

    • DATABASE_URL
    • WORKOS_API_KEY, WORKOS_CLIENT_ID, WORKOS_COOKIE_PASSWORD, WORKOS_REDIRECT_URI
    • Model provider keys (optional)
  2. Install:

    Terminal window
    pnpm add @workos-inc/authkit-nextjs
  3. Follow WorkOS AuthKit Next.js setup (middleware, callback route) as in the example README.

app/api/arivie/route.ts
/* SPDX-License-Identifier: Apache-2.0 */
import { getArivieRuntimeForOwner } from "../../../arivie.config";
import { resolveOwnerId } from "../../../lib/resolve-owner";
export async function POST(req: Request): Promise<Response> {
const ownerId = await resolveOwnerId(req);
const { arivie } = await getArivieRuntimeForOwner(ownerId);
return arivie.next.POST(req);
}
lib/resolve-owner.ts
/* SPDX-License-Identifier: Apache-2.0 */
import { withAuth } from "@workos-inc/authkit-nextjs";
import { BYPASS_OWNER_ID, isAuthBypassRequest } from "./auth-bypass";
export async function resolveOwnerId(req: Request): Promise<string> {
if (isAuthBypassRequest(req)) {
return BYPASS_OWNER_ID;
}
const { user } = await withAuth();
if (user?.id != null && user.id.length > 0) {
return user.id;
}
return process.env.ARIVIE_OWNER_ID ?? "with-workos-owner";
}

withAuth() supplies user.id as ownerId when present.

Terminal window
pnpm --filter with-workos dev

Canonical tree: arivie/examples/with-workos/.

Tested with @workos-inc/authkit-nextjs ^4.1.0.