Setup
-
Create the Synkro client
Create a shared module (e.g.
lib/synkro.ts) that exports a singleton client. The instance is initialized lazily on first call and survives HMR in development.lib/synkro.ts import { createSynkro } from "@synkro/next";export const synkro = createSynkro({transport: "redis",connectionUrl: process.env.REDIS_URL!,workflows: [{name: "order-fulfillment",triggerEvent: "order.created",steps: [{type: "validate",handler: async (payload) => {// validate orderreturn payload;},onSuccess: "process",},{type: "process",handler: async (payload) => {// process paymentreturn { ...payload, processed: true };},},],},],}); -
Configure Next.js
If you are using the Redis transport, add
ioredistoserverExternalPackagesso Next.js does not attempt to bundle it.next.config.ts import type { NextConfig } from "next";const nextConfig: NextConfig = {serverExternalPackages: ["ioredis"],};export default nextConfig; -
Set up the dashboard (optional)
Import
createDashboardHandlerand wire it to a catch-all route. See Route Handlers for the full example.