Skip to content

Commit

Permalink
update verifySignature function to use mux client instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjha committed Jan 12, 2024
1 parent 6843183 commit a9685ec
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pages/api/webhooks/mux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { getScores as moderationHive } from '../../../lib/moderation-hive';
import { autoDelete } from '../../../lib/moderation-action';

const webhookSignatureSecret = process.env.MUX_WEBHOOK_SIGNATURE_SECRET;
const mux = new Mux();

const verifyWebhookSignature = (rawBody: string | Buffer, req: NextApiRequest) => {
if (webhookSignatureSecret) {
// this will raise an error if signature is not valid
Mux.Webhooks.prototype.verifySignature(Buffer.isBuffer(rawBody) ? rawBody.toString('utf8') : rawBody, req.headers, webhookSignatureSecret)
mux.webhooks.verifySignature(Buffer.isBuffer(rawBody) ? rawBody.toString('utf8') : rawBody, req.headers, webhookSignatureSecret)
} else {
console.log('Skipping webhook sig verification because no secret is configured'); // eslint-disable-line no-console
}
Expand Down

0 comments on commit a9685ec

Please sign in to comment.