Skip to content

Commit

Permalink
add nextjs app router example
Browse files Browse the repository at this point in the history
  • Loading branch information
kleemeo committed Jun 27, 2023
1 parent c0e90c8 commit 31c916d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/receiving/verifying-payloads/how.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,42 @@ export default async function handler(req, res) {
}
```

### Node.js (Next.js 13 App Router)

```js
import { Webhook } from "svix";

const webhookSecret: string = process.env.WEBHOOK_SECRET || "your-secret";

export async function POST(req: Request) {
const svix_id = req.headers.get("svix-id") ?? "";
const svix_timestamp = req.headers.get("svix-timestamp") ?? "";
const svix_signature = req.headers.get("svix-signature") ?? "";

const body = await req.text();

const sivx = new Webhook(webhookSecret);

let msg;

try {
msg = sivx.verify(body, {
"svix-id": svix_id,
"svix-timestamp": svix_timestamp,
"svix-signature": svix_signature,
});
} catch (err) {
return new Response("Bad Request", { status: 400 });
}

console.log(msg);

// Rest

return new Response("OK", { status: 200 });
}
```
### Node.js (Netlify Functions)
```js
Expand Down

0 comments on commit 31c916d

Please sign in to comment.