[GH-ISSUE #1646] Stripe plugin with bun: SubtleCryptoProvider cannot be used in a synchronous context #8850

Closed
opened 2026-04-13 04:05:27 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @martiinii on GitHub (Mar 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1646

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Use bun + stripe plugin and set createCustomerOnSignUp to true. After trying to register, better-auth will throw an error SubtleCryptoProvider cannot be used in a synchronous context. (it's from stripe sdk, they don't support synchronous computation of hmac signature).

Current vs. Expected behavior

Every webhook from stripe is unhandled and results in error, when signing up an account record is also not created

Image

error: SubtleCryptoProvider cannot be used in a synchronous context.
  at new CryptoProviderOnlySupportsAsyncError (1:23)
  at computeHMACSignature (/node_modules/stripe/esm/crypto/SubtleCryptoProvider.js:21:11)

The error above comes from my debugging of stripe sdk (that is also thrown when webhook event is handled):

const stripeClient = new Stripe(Bun.env.STRIPE_SECRET_KEY!, {});

stripeClient.webhooks.generateTestHeaderString({
  payload: "",
  secret: Bun.env.STRIPE_WEBHOOK_SECRET!,
});
// ^ Will throw error in non node runtimes

Expected behavior: Handle all webhooks successfully outside node runtime

What version of Better Auth are you using?

1.2.0

Provide environment information

- Bun 1.2.4
- @better-auth/stripe 1.2.1
- stripe 17.7.0
- Elysia 1.2.12

Monorepo setup w/ turbo @2.4.0, dev is run through `bun -> turbo -> elysia -> better-auth`

Which area(s) are affected? (Select all that apply)

Package, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  plugins: [
    stripe({
      stripeClient,
      stripeWebhookSecret: Bun.env.STRIPE_WEBHOOK_SECRET!,
      createCustomerOnSignUp: true,
    }),
  ]
});

Additional context

The only way I've found is to use async version e.g generateTestHeaderStringAsync.
Could stripe plugin internals be changed to use respective async versions of stripe functions when handling webhooks? Then we would get full compatibility between runtimes.

Originally created by @martiinii on GitHub (Mar 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1646 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Use bun + stripe plugin and set `createCustomerOnSignUp` to `true`. After trying to register, better-auth will throw an error `SubtleCryptoProvider cannot be used in a synchronous context.` (it's from stripe sdk, they don't support synchronous computation of hmac signature). ### Current vs. Expected behavior Every webhook from stripe is unhandled and results in error, when signing up an `account` record is also not created ![Image](https://github.com/user-attachments/assets/822bb027-9688-48a8-bf17-d546a7dcb17d) ``` error: SubtleCryptoProvider cannot be used in a synchronous context. at new CryptoProviderOnlySupportsAsyncError (1:23) at computeHMACSignature (/node_modules/stripe/esm/crypto/SubtleCryptoProvider.js:21:11) ``` The error above comes from my debugging of stripe sdk (that is also thrown when webhook event is handled): ```ts const stripeClient = new Stripe(Bun.env.STRIPE_SECRET_KEY!, {}); stripeClient.webhooks.generateTestHeaderString({ payload: "", secret: Bun.env.STRIPE_WEBHOOK_SECRET!, }); // ^ Will throw error in non node runtimes ``` Expected behavior: Handle all webhooks successfully outside node runtime ### What version of Better Auth are you using? 1.2.0 ### Provide environment information ```bash - Bun 1.2.4 - @better-auth/stripe 1.2.1 - stripe 17.7.0 - Elysia 1.2.12 Monorepo setup w/ turbo @2.4.0, dev is run through `bun -> turbo -> elysia -> better-auth` ``` ### Which area(s) are affected? (Select all that apply) Package, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ plugins: [ stripe({ stripeClient, stripeWebhookSecret: Bun.env.STRIPE_WEBHOOK_SECRET!, createCustomerOnSignUp: true, }), ] }); ``` ### Additional context The only way I've found is to use async version e.g `generateTestHeaderStringAsync`. Could `stripe plugin` internals be changed to use respective async versions of stripe functions when handling webhooks? Then we would get full compatibility between runtimes.
GiteaMirror added the lockedstalebug labels 2026-04-13 04:05:27 -05:00
Author
Owner

@NeoPrint3D commented on GitHub (Mar 3, 2025):

I made a pull request fixing this issue

https://github.com/better-auth/better-auth/issues/1664

There is a temporary fix by just copying the files from the stripe plugin into your own project and change that single line referenced in the pull request

<!-- gh-comment-id:2695757559 --> @NeoPrint3D commented on GitHub (Mar 3, 2025): I made a pull request fixing this issue https://github.com/better-auth/better-auth/issues/1664 There is a temporary fix by just copying the files from the stripe plugin into your own project and change that single line referenced in the pull request
Author
Owner

@dosubot[bot] commented on GitHub (Jun 13, 2025):

Hi, @martiinii. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • The issue involves an error with the Stripe plugin when used with Bun, where SubtleCryptoProvider cannot be used synchronously.
  • This leads to unhandled webhooks and missing account records.
  • You suggested modifying the Stripe plugin to use asynchronous methods.
  • NeoPrint3D addressed the issue by creating a pull request with a fix and suggested a temporary workaround.

Next Steps:

  • Please let us know if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2970840782 --> @dosubot[bot] commented on GitHub (Jun 13, 2025): Hi, @martiinii. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - The issue involves an error with the Stripe plugin when used with Bun, where `SubtleCryptoProvider` cannot be used synchronously. - This leads to unhandled webhooks and missing account records. - You suggested modifying the Stripe plugin to use asynchronous methods. - NeoPrint3D addressed the issue by creating a pull request with a fix and suggested a temporary workaround. **Next Steps:** - Please let us know if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8850