-2

I am receiving a webhook from patreon, and when I fire the test, I get this error:

(node:636) UnhandledPromiseRejectionWarning: ReferenceError: event is not defined

This is the code I have

const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.post('/', async (req, res) => {
    let crypto = require('crypto');

    let hash = event.headers['X-Patreon-Signature'],
        hmac = crypto.createHmac("md5", 'patreon-secret-removed ;)'); 

    hmac.update(event.body);

    let crypted = hmac.digest("hex");

    if (crypted === hash) {
        console.log("That's good hash! " + hash);
    } else {
        console.log("Bad hash! " + hash + " crypted " + crypted);
    }
})
app.listen(8080)

How would I replace event or define it?

Bob joe12
  • 103
  • 22
  • 1
    Did you mean to write ``req.headers['X-Patreon-Signature']`` and ``req.body``? – Take-Some-Bytes Sep 24 '21 at 03:29
  • Now i get the error (node:1009) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined – Bob joe12 Sep 24 '21 at 03:41
  • That's because you didn't use body parser correctly. See https://stackoverflow.com/questions/10005939/how-do-i-consume-the-json-post-data-in-an-express-application – Take-Some-Bytes Sep 24 '21 at 04:10
  • Nice copy & paste error. `event` is undefined because its not declared. I guess you mean `req` instead of `event`... – Marc Sep 24 '21 at 12:57

1 Answers1

2

let hash = event.headers['X-Patreon-Signature'] << what is event?

Maybe it's a req, not an event.

kim young chan
  • 300
  • 1
  • 13
  • Now i get the error Now i get the error (node:1009) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined – – Bob joe12 Sep 25 '21 at 17:49