Skip to content

Resolve APP_URL before the checkout try, and move to SDK rc.9 - #2

Merged
Evy04 merged 2 commits into
mainfrom
fix/checkout-config-and-rc9
Aug 14, 2026
Merged

Resolve APP_URL before the checkout try, and move to SDK rc.9#2
Evy04 merged 2 commits into
mainfrom
fix/checkout-config-and-rc9

Conversation

@Evy04

@Evy04 Evy04 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

The bug

appUrl() was called inside the try/catch around createCheckout:

try {
  const { url } = await rekey().billing.createCheckout(session.accessToken, {
    successUrl: `${appUrl()}/library?bought=${slug}`,   // throws in here
    ...

So a missing APP_URL was caught alongside declined cards and archived plans,
and rendered to the buyer as "Could not start checkout". An operator's
misconfiguration reported as a payment failure, with the one sentence naming
the real cause swallowed on the way out.

This is not hypothetical: the same bug on nextjs-starter cost an afternoon.
Checkout looked broken end to end when one variable was blank.

The fix

Configuration is resolved before the try, so it escapes as a real error. The
catch still covers genuine checkout failures, which correctly surface the API's
own message.

The helper moves to lib/app-url.ts to match the starter. It stays a throw
rather than becoming a boot-time check because next build runs on machines
with no environment at all, which is most CI: failing at import would break the
build rather than the request that actually needs the value. lib/rekey.ts is
lazy for the same reason.

Also

@rekey.dev/* from rc.6 to rc.9. That carries the restyled drop-in
components and the RekeyProvider fix where any failed /auth/me refetch
signed the user out.

Verification

tsc --noEmit clean; npm run build clean; the built server booted and
/, /p/grid-icons and /sign-in all return 200 with the expected content. A
green build alone was not treated as evidence.

Mizety added 2 commits August 13, 2026 22:37
appUrl() was called inside the try/catch around createCheckout, so a missing
APP_URL was caught alongside declined cards and a missing provider, and
reported to the buyer as 'Could not start checkout'. An operator's
misconfiguration was being shown as a payment failure, and the one sentence
naming the real cause was destroyed on the way. The same bug cost an afternoon
on the Next.js starter, where checkout looked broken end to end because one
variable was blank.

Configuration is now read before the try, so it escapes as a real error. The
catch still covers genuine checkout failures, which correctly surface the API's
own message.

The helper moves to lib/app-url.ts to match the starter, and keeps the throw
rather than becoming a boot-time check: next build runs on machines with no
environment at all, which is most CI, so failing at import would break the
build instead of the request that actually needs the value. lib/rekey.ts is
lazy for the same reason.

Also moves @rekey.dev/* from rc.6 to rc.9, which carries the restyled drop-in
components and the RekeyProvider fix where any failed /auth/me refetch signed
the user out.

Verified by building and booting the built server: /, /p/grid-icons and
/sign-in all serve, and tsc is clean.
Ported from nextjs-starter, where clicking Buy against a live API showed a
customer this in the product card, verbatim from the API:

  This subscriber pays through "paypal", which is no longer configured for
  this Application. ... Re-add the "paypal" credentials in Panel ->
  Application -> Billing ...

It talks about the buyer in the third person and its only instruction needs a
panel they do not have.

lib/rekey-error.ts maps the handful of codes whose text is addressed to the
operator onto one sentence a customer can act on, logs the real message and fix
to the server console, and passes everything else through unchanged. A declined
card or an archived product is the buyer's situation and the API already says
so in words they can use.
@Evy04
Evy04 merged commit ffc2393 into main Aug 14, 2026
@Evy04
Evy04 deleted the fix/checkout-config-and-rc9 branch August 14, 2026 01:09
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

Successfully merging this pull request may close these issues.

2 participants