Capítulo 515 de 988

Chapter 515: validateWebhookSignature()

Core Idea

<AvailableFrom v="3. 2.

Key Concepts

  • API
  • secret
  • body
  • signatureHeader
  • Example
  • See also

Code Examples

type NextApiRequest = {
  body: object;
  headers: Record<string, string>;
};
type NextApiResponse = {
  status: (code: number) => {json: (body: object) => void};
};

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  validateWebhookSignature({
    secret: process.env.WEBHOOK_SECRET as string,
    body: req.body,
    signatureHeader: req.headers['x-remotion-signature'] as string,
  });

  // If code reaches this path, the webhook is authentic.
  const payload = req.body as WebhookPayload;
  if (payload.type === 'success') {
    // ...
  } else if (payload.type === 'timeout') {
    // ...
  }

  res.status(200).json({
    success: true,
  });
}
  • What it demonstrates: Usage pattern for validateWebhookSignature() from the official docs.

Key Takeaways

  1. Understand api when working with validateWebhookSignature().
  2. Understand secret when working with validateWebhookSignature().
  3. Understand body when working with validateWebhookSignature().
  4. Understand signatureheader when working with validateWebhookSignature().
  5. Understand example when working with validateWebhookSignature().

Connects To

  • api: related page in the Lambda (@remotion/lambda) section.
  • Approuterwebhook: related page in the Lambda (@remotion/lambda) section.
  • Authentication: related page in the Lambda (@remotion/lambda) section.