Lemon Squeezy webhook fails: "Invalid signature" or the plan never unlocks

Error: Invalid signature. (your X-Signature check fails), or the Lemon Squeezy webhook log shows failed deliveries and the order never reaches your app

What you see

You added Lemon Squeezy checkout to an app built with Lovable, Bolt, Cursor or v0. The test purchase goes through and the order shows up in your Lemon Squeezy dashboard, but your app never marks the user as paid. In your server logs you find:

Error: Invalid signature.

That’s the error thrown by the Node example in Lemon Squeezy’s docs, which AI builders copy almost word for word. Or there’s nothing in your logs at all, because the request never reached your code.

Start in Lemon Squeezy under Settings » Webhooks. Recent webhooks are logged there with the full payload of each request, and you can resend them from the same page.

How the signature works

When you create a webhook you pick a signing secret, any string from 6 to 40 characters. For every request, Lemon Squeezy computes an HMAC SHA-256 hex digest of the request body with that secret and sends it in the X-Signature header. Each request also carries Content-Type: application/json and an X-Event-Name header such as order_created.

Your server repeats the calculation and compares. It fails when either input is different from what Lemon Squeezy used:

  1. The secret is different. The value in your host’s environment variables isn’t the one typed into the webhook. Common causes are a placeholder like SIGNING_SECRET left in the code, a variable set only for preview deployments, a trailing space or newline, or a webhook recreated with a new secret.
  2. The body is different. The hash covers the exact bytes Lemon Squeezy sent. If your framework parses the JSON first and you hash JSON.stringify(body), the bytes can change and the digest won’t match.

Fix 1: the same secret on both sides

  1. In Settings » Webhooks, open the webhook and set a signing secret you control (generate a long random string and stay within the 40-character limit).
  2. Put exactly that value in your host’s environment variables, for example LEMONSQUEEZY_WEBHOOK_SECRET, for the production environment.
  3. Redeploy so the running app picks up the new value.

Fix 2: hash the raw body

Lemon Squeezy’s own Node example:

import crypto from 'node:crypto';

const secret = process.env.LEMONSQUEEZY_WEBHOOK_SECRET;
const hmac = crypto.createHmac('sha256', secret);
const digest = Buffer.from(hmac.update(request.rawBody).digest('hex'), 'utf8');
const signature = Buffer.from(request.get('X-Signature') || '', 'utf8');

if (!crypto.timingSafeEqual(digest, signature)) {
  throw new Error('Invalid signature.');
}

The important part is request.rawBody: the unparsed body. How you get it depends on the stack:

  • Next.js App Router route handler (v0, Cursor): read const rawBody = await request.text() and hash that. Only call JSON.parse(rawBody) after the check passes. Don’t call request.json() first, because the body can only be read once.
  • Express: give the webhook route express.raw({ type: 'application/json' }) and register it before app.use(express.json()), so the JSON parser doesn’t consume the body first.
  • Supabase Edge Functions (Lovable, Bolt): read await req.text(), then compute the HMAC with Web Crypto (crypto.subtle) and compare the hex string to req.headers.get('X-Signature').

One more trap in that snippet: Node’s crypto.timingSafeEqual throws an error when the two buffers have different byte lengths. A missing or truncated header therefore throws instead of returning false. Catch it and respond 400 rather than letting it crash as a 500.

Fix 3: Supabase Edge Function returns 401

Supabase Edge Functions require a valid JWT by default, and Lemon Squeezy doesn’t send one, so every delivery is rejected before your code runs. Turn the check off for that one function in supabase/config.toml:

[functions.lemonsqueezy-webhook]
verify_jwt = false

The function is now callable by anyone, which is why the X-Signature check is not optional.

Fix 4: it worked in test mode, nothing arrives in live mode

Your store starts in test mode. Lemon Squeezy’s docs say test-mode products don’t carry over to live mode automatically, and test-mode API keys only touch test data. Webhooks are flagged too: the webhook object has a test_mode attribute for whether it was created in test mode.

So after activating your store:

  1. Switch the dashboard out of test mode and open Settings » Webhooks.
  2. Check that a webhook exists there, that it points at your production URL (not localhost, not a tunnel, not a preview deployment behind a password), and that it subscribes to the events your code handles.
  3. If you call the Lemon Squeezy API from your app, swap in a live-mode API key as well.

If the URL is HTTPS, Lemon Squeezy verifies its SSL certificate before sending, so an expired or misconfigured certificate also stops deliveries.

Fix 5: return 200 quickly, expect duplicates

Lemon Squeezy treats any status other than 200 as a failure. It retries up to three more times with exponential backoff (their example: 5, 25 and 125 seconds), then gives up. After that, the only way to get the event again is to resend it from the webhooks settings page.

  • Return 200, not 201 or 204. Do the slow work (emails, provisioning) after storing the event. Lemon Squeezy’s developer guide recommends storing events locally first so you can respond fast and debug later.
  • Make it idempotent. The same event can arrive more than once because of retries and manual resends. The event types page also says order_created is always sent alongside subscription_created. If both handlers “grant one month of access” or “add credits”, the customer gets them twice. Key your updates on the Lemon Squeezy order or subscription ID and set the status instead of incrementing it.

Know which user paid

Don’t match buyers by email; people check out with a different address than they signed up with. Pass your own user ID through the checkout as custom data. Lemon Squeezy returns it in meta.custom_data on order, subscription and license key events:

{ "meta": { "event_name": "order_created", "custom_data": { "user_id": 123 } } }

Check it worked

  1. In test mode, buy your product with a test card such as 4242 4242 4242 4242 and any future expiry date.
  2. In Settings » Webhooks, the delivery succeeded, and your app shows the user as paid exactly once.
  3. For renewals and cancellations, open a test subscription and use Simulate event in its side panel. subscription_payment_* events can only be simulated after a real test renewal has happened, so use a product with a daily billing interval.
  4. When the first real order comes in, check its delivery in the live-mode webhook log. That confirms the live webhook and secret work too.