Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for changes in SvelteKit that remove rawBody #6

Open
brunobely opened this issue Feb 5, 2022 · 6 comments
Open

Update for changes in SvelteKit that remove rawBody #6

brunobely opened this issue Feb 5, 2022 · 6 comments

Comments

@brunobely
Copy link

brunobely commented Feb 5, 2022

Since sveltejs/kit#3384, rawBody is no longer exposed in endpoints. I have not found a way to correctly pass the original request into Stripe's constructEvent to verify the event signature. I'd love to know if you think that can be done and how.

@evdama
Copy link

evdama commented Feb 17, 2022

Seems in hooks.js handle() function you can just use event.request in order to get the original request coming in from the client

See sveltejs/kit#3384

@WeAreELIC
Copy link

Hey, I'm also using Stripe's API and need the rawBody from an endpoints post function. How do we get the raw request body now?

@kylebuildsstuff
Copy link

Hey, I'm also using Stripe's API and need the rawBody from an endpoints post function. How do we get the raw request body now?

I found this to work for me:

const _rawBody = await event.request.arrayBuffer();
const rawBody = toBuffer(_rawBody);

stripeEvent = stripe.webhooks.constructEvent(
      rawBody,
      stripeSignature,
      process.env.STRIPE_WEBHOOK_SECRET
    );

@kvetoslavnovak
Copy link

Hey, I'm also using Stripe's API and need the rawBody from an endpoints post function. How do we get the raw request body now?

I found this to work for me:

const _rawBody = await event.request.arrayBuffer();
const rawBody = toBuffer(_rawBody);

stripeEvent = stripe.webhooks.constructEvent(
      rawBody,
      stripeSignature,
      process.env.STRIPE_WEBHOOK_SECRET
    );

I had the need of rawbody recently and have used the same pattern.

@fcrozatier
Copy link

You can remove the toBuffer function with a Buffer.from call. Something like this

const rawBody = Buffer.from(await request.arrayBuffer());

@pierre-H
Copy link

pierre-H commented Jan 5, 2023

Does anyone has a solution ... None of these worked for me ... 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants