This example demonstrates an authentication provider webhook process using Upstash Workflow. The workflow handles the user creation, trial management, email reminders and notifications.

Use Case

Our workflow will:

  1. Receive a webhook event from an authentication provider (e.g. Firebase, Auth0, Clerk etc.)
  2. Create a new user in our database
  3. Create a new user in Stripe
  4. Start a trial in Stripe
  5. Send a welcome email
  6. Send a reminder email if the user hasn’t solved any questions in the last 7 days
  7. Send a trial warning email if the user hasn’t upgraded 2 days before the trial ends
  8. Send a trial ended email if the user hasn’t upgraded

Code Example

Code Breakdown

1. Sync User

We start by creating a new user in our database:

2. Create New User in Stripe

Next, we create a new user in Stripe:

3. Start Trial in Stripe

We start a trial in Stripe:

4. Send Welcome Email

We send a welcome email to the user:

5. Send Reminder Email

After 7 days, we check if the user has solved any questions. If not, we send a reminder email:

The sendProblemSolvedEmail method:

6. Send Trial Warning Email

If the user hasn’t upgraded 2 days before the trial ends, we send a trial warning email:

If they upgraded, we end the workflow by returning.

7. Send Trial Ended Email

If the user hasn’t upgraded after the trial ends, we send a trial ended email: