Jan 24, 2024
Domitrius Clark
We are excited to announce that Clerk has teamed up with Inngest and Svix to integrate with external systems reliably.
In this post we will dive into how the collaboration between Clerk, Inngest, and Svix enhances your authentication workflows using Clerk’s new Inngest webhook transformation template.
Clerk webhooks (powered by Svix) allow you to receive event notifications from Clerk. When a user.created
event is triggered, you may want to:
Today, with Clerk’s new Inngest webhook transformation template, you can easily use Clerk webhook events to trigger Inngest functions.
Inngest is a reliability layer for your application. Using it comes with a few key benefits such as managing concurrency, automatic retries, parallel execution, complex workflows, or task scheduling. This approach eliminates concerns about operating and scaling webhooks or error handling.
The code below features the inngest.createFunction
method, which inserts a new user into the database. It will be triggered whenever a clerk/user.created
event occurs.
const syncUser = inngest.createFunction({ id: 'sync-user-from-clerk' },{ event: 'clerk/user.created' }, // ← This is the function's triggering eventasync ({ event }) => {const user = event.data; // The event payload's data will be the Clerk User json objectconst { id, first_name, last_name } = user;const email = user.email_addresses.find(e =>e.id === user.primary_email_address_idawait database.users.insert({ id, email, first_name, last_name })})
You can also have multiple functions react to the same event. The code below uses step.sleep
to send a welcome email, then wait for three days, then follow up with a message offering a free trial:
const sendOnboardingEmails = inngest.createFunction({ id: 'onboarding-emails' },{ event: 'clerk/user.created' },async ({ event, step }) => { // ← step is available in the handler's argumentsconst { user } = event.dataconst { first_name } = userconst email = user.email_addresses.find(e =>e.id === user.primary_email_address_idawait step.run('welcome-email', async () => {await emails.sendWelcomeEmail({ email, first_name })})// wait 3 days before second emailawait step.sleep('wait-3-days', '3 days')await step.run('trial-offer-email', async () => {await emails.sendTrialOfferEmail({ email, first_name })})})
To learn how to integrate Inngest into your workflows, check out Clerk's official integration guide or refer to Inngest documentation.
As we continue to relentlessly improve the Developer Experience of our products, we are excited to see what developers build using the Inngest integration.
Start completely free for up to 10,000 monthly active users and up to 100 monthly active orgs. No credit card required.
Learn more about our transparent per-user costs to estimate how much your company could save by implementing Clerk.
The latest news and updates from Clerk, sent to your inbox.