How to Setup Mux Web Hooks with React Native Firebase Functions

How to Setup Mux Web Hooks with React Native Firebase Functions

Let's jump right into it

1. Create/deploy a new firebase function


2. Create a web hook in your Mux dashboard and connect it to your firebase function url (i.e. https://us-central1-spring-ranger-281214.cloudfunctions.net/muxEvents)


3. Insert the following code in your firebase functions:
exports.muxEvents = functions.https.onRequest((request, response) => {
try {
const sig = request.headers['mux-signature'];
// returns a `boolean` with value `true` if the signature is valid
const isValidSignature = Webhooks.verifyHeader(request.rawBody, sig,
MUX_WEBHOOK_SECRET);
console.log('Success:', isValidSignature);
// convert the raw req.body to JSON, which is originally Buffer (raw)
const jsonFormattedBody = JSON.parse(request.rawBody);
// await doSomething();
response.json({ received: true });
} catch (err) {
  res.status(400).send(`Webhook Error: ${err.message}`);
}
});


4) Deploy function and you’re set to go

Related Posts