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.
-
Copy
examples/with-workos/.env.exampleand configure:DATABASE_URLWORKOS_API_KEY,WORKOS_CLIENT_ID,WORKOS_COOKIE_PASSWORD,WORKOS_REDIRECT_URI- Model provider keys (optional)
-
Install:
Terminal window pnpm add @workos-inc/authkit-nextjs -
Follow WorkOS AuthKit Next.js setup (middleware, callback route) as in the example README.
Route handler
Section titled “Route handler”/* 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);}ownerId derivation
Section titled “ownerId derivation”/* 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.
Runnable example
Section titled “Runnable example”pnpm --filter with-workos devCanonical tree: arivie/examples/with-workos/.
Tested with @workos-inc/authkit-nextjs ^4.1.0.