Refactor webhook signature verification process
The signature verification process for webhooks has been abstracted. Instead of performing the check directly in the handleWebhook method, it has been moved to a separate service class: PostgresDatabaseWebhookVerifierService. This refactor improves modularity and enables extending or replacing the verification logic more comfortably. The WEBHOOK_SENDER_PROVIDER environment variable is used to determine which verifier service to use.
This commit is contained in:
@@ -1,15 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { DatabaseWebhookHandlerService } from '@kit/database-webhooks';
|
||||
|
||||
const webhooksSecret = z
|
||||
.string({
|
||||
description: `The secret used to verify the webhook signature`,
|
||||
required_error: `Provide the variable SUPABASE_DB_WEBHOOK_SECRET. This is used to authenticate the webhook event from Supabase.`,
|
||||
})
|
||||
.min(1)
|
||||
.parse(process.env.SUPABASE_DB_WEBHOOK_SECRET);
|
||||
|
||||
const service = new DatabaseWebhookHandlerService();
|
||||
|
||||
const response = (status: number) => new Response(null, { status });
|
||||
@@ -23,7 +13,7 @@ const response = (status: number) => new Response(null, { status });
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
// handle the webhook event
|
||||
await service.handleWebhook(request, webhooksSecret);
|
||||
await service.handleWebhook(request);
|
||||
|
||||
return response(200);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user