Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(/integrations/webhooks/sync-data) update guide #1655

Merged
merged 57 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
44866cc
wip
victoriaxyz Oct 25, 2024
32685cc
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Oct 25, 2024
8ca1405
wip
victoriaxyz Oct 29, 2024
ca3c5e4
wip
victoriaxyz Oct 29, 2024
dc5276d
fix
victoriaxyz Oct 29, 2024
110fbe7
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
a9ee917
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
2bf4fc5
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
c037c39
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
a7871d0
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
0887bb0
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
13adc1e
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
822516f
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
a61a726
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
2ed560e
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
8eabba5
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Oct 30, 2024
313d288
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
5737357
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
9e87464
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
c016f9a
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
5d2f44f
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
7cd914d
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
4ee9534
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
d69119d
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
c249cb2
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
88e34c1
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 30, 2024
c29a20b
lint
victoriaxyz Oct 30, 2024
ef0d019
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Oct 31, 2024
4726240
fix
victoriaxyz Oct 31, 2024
99ccb1c
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
831f354
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
770f3c7
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
273c94d
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
7f47a3e
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
683fd7e
fix msg and add link
victoriaxyz Oct 31, 2024
996983b
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
df7e442
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Oct 31, 2024
81e555d
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 1, 2024
85e9856
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 1, 2024
eb60c29
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 1, 2024
b0306ce
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 1, 2024
2873fae
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 4, 2024
4d62c3b
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 5, 2024
2a00852
update
victoriaxyz Nov 5, 2024
23cff81
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 8, 2024
362ff06
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 8, 2024
628e0ac
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 8, 2024
1c4ff85
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 8, 2024
9667eb6
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 13, 2024
e0653fd
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 13, 2024
7596e6c
Update docs/integrations/webhooks/sync-data.mdx
victoriaxyz Nov 13, 2024
51d6488
remove extra paragraph and fix wording
victoriaxyz Nov 13, 2024
37d4954
lint
victoriaxyz Nov 13, 2024
43f2b65
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 14, 2024
4018e89
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 14, 2024
280b6b1
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 15, 2024
c194064
Merge branch 'main' into vi/docs-8861/sync-data
victoriaxyz Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions docs/integrations/webhooks/sync-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ These steps apply to any Clerk event. To make the setup process easier, it's rec

### Set up a webhook endpoint

To set up a webhook endpoint, you must provide the **Endpoint URL** and choose the events you want to listen to. For this guide, select the `user.created` event.

1. In the Clerk Dashboard, navigate to the [**Webhooks**](https://dashboard.clerk.com/last-active?path=webhooks) page.
1. Select **Add Endpoint**.
1. In the **Endpoint URL** field, paste the ngrok **Forwarding** URL you saved earlier, followed by `/api/webhooks`. This is the endpoint that Svix uses to send the webhook payload. The full URL should resemble `https://fawn-two-nominally.ngrok-free.app/api/webhooks`.
Expand All @@ -78,27 +76,13 @@ These steps apply to any Clerk event. To make the setup process easier, it's rec

Incoming webhook events have no auth information. They come from an external source and will not be signed in or signed out. To allow access, the route must be public.

The following example shows the recommended Middleware configuration for webhook routes.

```ts {{ filename: 'middleware.ts' }}
import { clerkMiddleware } from '@clerk/nextjs/server'

// Make sure that the `/api/webhooks(.*)` route is not protected here
export default clerkMiddleware()
Incoming webhook events contain no authentication information. They come from an external source and won't be signed in or signed out, so the route must be public to allow access.

export const config = {
matcher: [
// Skip Next.js internals and all static files, unless found in search params
'/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
// Always run for API routes
'/(api|trpc)(.*)',
],
}
```
To configure your Middleware, refer to the [clerkMiddleware() guide](docs/references/nextjs/clerk-middleware).
Copy link
Member

Choose a reason for hiding this comment

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

looks like you repeat information here.
also the sentence ends wtih "so the route must be public to allow access". and then the next sentence goes into configuring your middleware.

there should be some relational information that ties these two concepts together:
"so the route must be public to allow access. If you are using clerkMiddleware(), you will need to ensure that the /api/webhooks(.*) route is public. For more information on configuring routes with clerkMiddleware(), see the reference.

also don't forget that clerkMiddleware() always needs to be in code snippets. even if it's in a link

Copy link
Contributor Author

Choose a reason for hiding this comment

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


### Install `svix`

You'll use [`svix`](https://www.npmjs.com/package/svix) to verify the webhook signature. Run the following command in your terminal to install it:
Clerk uses [`svix`](https://www.npmjs.com/package/svix) to deliver webhooks, so you'll need the package to verify the webhook signature. Run the following command in your terminal to install it:
royanger marked this conversation as resolved.
Show resolved Hide resolved

<CodeBlockTabs type="installer" options={["npm", "yarn", "pnpm"]}>
victoriaxyz marked this conversation as resolved.
Show resolved Hide resolved
```bash {{ filename: 'terminal' }}
Expand All @@ -116,11 +100,13 @@ These steps apply to any Clerk event. To make the setup process easier, it's rec

### Create the endpoint

Set up a Route Handler that uses `svix` to verify the webhook and process the payload.
Set up a Route Handler that uses `svix` to verify the incoming Clerk webhook and process the payload.

For this guide, the payload will be logged to the console. In a real app, you'd use the payload to trigger an action. For example, if listening for the `user.created` event, you might perform a database `create` or `upsert` to add the user's details to the user's table.

The webhook must return either an [error code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses) such as `405` or `403` or a [success code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses), such as `200` or `201`. An error code will appear in the Clerk Dashboard log and trigger a [retry](/docs/integrations/webhooks/overview#retry). A success code will stop further retries and show a success status in the Clerk Dashboard log.
If the route handler returns a [2xx code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#successful_responses), the event will be marked as successful, and retries will stop. If the route handler returns a [4xx](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses) or [5xx code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses), or no code at all, the webhook event will be [retried](/docs/integrations/webhooks/overview#retry).

In summary, a 2xx (success) code stops retries, while any other response is considered a failure and will trigger retries.
victoriaxyz marked this conversation as resolved.
Show resolved Hide resolved

> [!NOTE]
> The following Route Handler can be used for any webhook event you choose to listen to, not just `user.created`.
Expand Down
Loading