Skip to content

Conversation

SarahSoutoul
Copy link
Contributor

@SarahSoutoul SarahSoutoul commented Sep 30, 2025

Description

Fixes: https://linear.app/clerk/issue/DOCS-10999/feedback-for-referencebackendverify-webhook

Adds missing import for verifyWebhook.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Documentation

    • Improved webhook verification docs with a clearer inline example showing import and usage within a POST handler; example reorganized for readability. No runtime behavior changed.
  • Chores

    • Added a placeholder changeset file to track upcoming changes and release notes.

Copy link

vercel bot commented Sep 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Skipped Skipped Sep 30, 2025 10:04pm

Copy link

changeset-bot bot commented Sep 30, 2025

🦋 Changeset detected

Latest commit: c398985

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 30, 2025

Walkthrough

Updated inline documentation in packages/backend/src/webhooks.ts to expand the verifyWebhook usage example (import and POST handler pattern). Added a placeholder changeset file at .changeset/calm-yaks-ring.md. No runtime, API, or exported-entity changes.

Changes

Cohort / File(s) Summary
Docs: verifyWebhook examples
packages/backend/src/webhooks.ts
Expanded the doc comment example to show importing verifyWebhook from @clerk/backend/webhooks, wrapping it in an exported POST handler, extracting event data after verification, and using try/catch-return responses. No code logic changed.
Changeset placeholder
.changeset/calm-yaks-ring.md
Added an empty/placeholder changeset file containing only frontmatter delimiter lines (---).

Sequence Diagram(s)

(omitted — changes are documentation-only and do not modify control flow)

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

I twitch my nose at lines anew,
A snippet hops in, tidy and true.
No paths were altered, just clearer tracks,
A tiny changeset tucked in my sacks.
Thump-thump, I cheer — docs fresh as dew. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly identifies the primary change of adding the missing import for verifyWebhook in the backend documentation example, concisely and accurately reflecting the PR’s scope as documentation-only.
Linked Issues Check ✅ Passed The pull request updates the documentation code example to import verifyWebhook from the correct package path and demonstrates its usage in an exported POST handler with try/catch as requested in DOCS-10999, fully addressing the linked issue’s requirement to reflect actual package exports.
Out of Scope Changes Check ✅ Passed All modifications are confined to updating the inline documentation example for verifyWebhook and adding a placeholder changeset entry, which are directly related to documenting the new import and release process; no unrelated code paths or features were altered.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ss/DOCS-10999

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@NWylynko
Copy link
Contributor

Thoughts on wrapping it in a function?

import { verifyWebhook } from "@clerk/backend/webhooks";

export async function POST(request: Request) {
  try {
    const evt = await verifyWebhook(request);

    // Access the event data
    const { id } = evt.data;
    const eventType = evt.type;

    // Handle specific event types
    if (eventType === "user.created") {
      console.log("New user created:", id);
      // Handle user creation
    }

    return new Response("Success", { status: 200 });
  } catch (err) {
    console.error("Webhook verification failed:", err);
    return new Response("Webhook verification failed", { status: 400 });
  }
}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between df52b0b and 678ce8d.

📒 Files selected for processing (1)
  • .changeset/huge-clouds-clap.md (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/huge-clouds-clap.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (30)
  • GitHub Check: Integration Tests (custom, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (machine, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (sessions:staging, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: Static analysis
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan

Copy link

pkg-pr-new bot commented Sep 30, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6895

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6895

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6895

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6895

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6895

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6895

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6895

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6895

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6895

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6895

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6895

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6895

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6895

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6895

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6895

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6895

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6895

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6895

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6895

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6895

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6895

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6895

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6895

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6895

commit: c398985

@SarahSoutoul
Copy link
Contributor Author

SarahSoutoul commented Sep 30, 2025

Thoughts on wrapping it in a function?

import { verifyWebhook } from "@clerk/backend/webhooks";

export async function POST(request: Request) {
  try {
    const evt = await verifyWebhook(request);

    // Access the event data
    const { id } = evt.data;
    const eventType = evt.type;

    // Handle specific event types
    if (eventType === "user.created") {
      console.log("New user created:", id);
      // Handle user creation
    }

    return new Response("Success", { status: 200 });
  } catch (err) {
    console.error("Webhook verification failed:", err);
    return new Response("Webhook verification failed", { status: 400 });
  }
}

@NWylynko Done here: Wrap into function.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 678ce8d and 740545f.

📒 Files selected for processing (2)
  • .changeset/calm-yaks-ring.md (1 hunks)
  • packages/backend/src/webhooks.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/backend/src/webhooks.ts
🧰 Additional context used
📓 Path-based instructions (1)
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/calm-yaks-ring.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (handshake, chrome)
  • GitHub Check: Integration Tests (handshake:staging, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/backend/src/webhooks.ts (2)

68-87: Minor TS polish in the example: add explicit return type and avoid an unused variable.

  • Add : Promise<Response> to POST for clarity.
  • Either use eventType in the conditional or drop it to avoid ESLint “unused var” when users copy/paste.
-export async function POST(request: Request) {
+export async function POST(request: Request): Promise<Response> {
   try {
     const evt = await verifyWebhook(request)

     // Access the event data
     const { id } = evt.data
-    const eventType = evt.type
+    const eventType = evt.type

     // Handle specific event types
-    if (evt.type === 'user.created') {
+    if (eventType === 'user.created') {
       console.log('New user created:', evt.data.id)
       // Handle user creation
     }

83-86: Docs example: narrow unknown error before logging; optional JSON response for DX.

Keeps the snippet robust across runtimes and avoids noisy logs.

-  } catch (err) {
-    console.error('Webhook verification failed:', err)
-    return new Response('Webhook verification failed', { status: 400 })
+  } catch (err: unknown) {
+    const message = err instanceof Error ? err.message : String(err)
+    console.error('Webhook verification failed:', message)
+    return new Response(JSON.stringify({ error: 'Webhook verification failed', message }), {
+      status: 400,
+      headers: { 'content-type': 'application/json' },
+    })
   }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 740545f and 7b3fb1a.

📒 Files selected for processing (1)
  • packages/backend/src/webhooks.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/backend/src/webhooks.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/backend/src/webhooks.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/backend/src/webhooks.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/backend/src/webhooks.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoid any type - prefer unknown when type is uncertain, then narrow with type guards
Use interface for object shapes that might be extended
Use type for unions, primitives, and computed types
Prefer readonly properties for immutable data structures
Use private for internal implementation details
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/backend/src/webhooks.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/backend/src/webhooks.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build Packages
🔇 Additional comments (1)
packages/backend/src/webhooks.ts (1)

66-66: Approve import: webhooks subpath export present.

The ./webhooks subpath is declared in packages/backend/package.json and verifyWebhook is exported; ready to merge.

@SarahSoutoul SarahSoutoul merged commit 83b4cff into main Sep 30, 2025
41 checks passed
@SarahSoutoul SarahSoutoul deleted the ss/DOCS-10999 branch September 30, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants