Skip to main content
POST
Clerk Webhook

Overview

This webhook endpoint receives user lifecycle events from Clerk authentication service. It automatically syncs user data between Clerk and the SkillRise database.

Authentication

Webhook Signature Verification

Clerk uses Svix for webhook delivery. All requests are verified using HMAC signatures. Required Headers:
  • svix-id: Unique message identifier
  • svix-timestamp: Unix timestamp when the webhook was sent
  • svix-signature: HMAC signature for verification
Verification Process: The endpoint verifies the webhook signature using the CLERK_WEBHOOK_SECRET environment variable:
Failed signature verification results in an error being thrown and the webhook being rejected.

Event Types

user.created

Fired when a new user signs up through Clerk. Action: Creates a new user record in the SkillRise database. Payload Example:
Database Fields:
  • _id: Clerk user ID
  • email: Primary email address
  • name: Concatenation of first_name and last_name
  • imageUrl: Profile image URL

user.updated

Fired when a user updates their profile in Clerk. Action: Updates the existing user record in the database. Payload Example:
Updated Fields:
  • email
  • name
  • imageUrl

user.deleted

Fired when a user account is deleted in Clerk. Action: Deletes the corresponding user record from the database. Payload Example:

Request Format

Headers

Body

Response Format

Success Response

Status Code: 200 OK
All successful webhook processing returns an empty JSON object.

Error Response

Status Code: 500 Internal Server Error

Error Handling

The endpoint implements comprehensive error handling:
  1. Signature Verification Failure: If the Svix signature verification fails, an error is thrown and caught by the error handler
  2. Database Errors: Any database operation failures are caught and return a 500 error
  3. Unknown Event Types: Events with unrecognized types are silently acknowledged with an empty response
Unknown event types return a successful empty response to prevent Clerk from retrying the webhook.

Security Best Practices

  1. Environment Variables: Store CLERK_WEBHOOK_SECRET securely in environment variables
  2. Signature Verification: Always verify the Svix signature before processing any webhook data
  3. HTTPS Only: Configure Clerk to only send webhooks to HTTPS endpoints in production
  4. Idempotency: The endpoint handles duplicate webhooks gracefully (e.g., update operations are idempotent)

Configuration

Clerk Dashboard Setup

  1. Navigate to Webhooks in your Clerk dashboard
  2. Click Add Endpoint
  3. Enter your endpoint URL: https://yourdomain.com/clerk
  4. Select events to subscribe to:
    • user.created
    • user.updated
    • user.deleted
  5. Copy the Signing Secret and set it as CLERK_WEBHOOK_SECRET

Environment Variables

Implementation Reference

Location: server/controllers/webhooks.js:8