Polar customer creation error doesn't prevent better auth user creation #1033

Closed
opened 2026-03-13 08:19:48 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @proevilz on GitHub (Apr 13, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Follow the tutorial on how to setup Polar with Better Auth.

import { betterAuth } from "better-auth";
import { polar } from "@polar-sh/better-auth";
import { Polar } from "@polar-sh/sdk";

const client = new Polar({
    accessToken: process.env.POLAR_ACCESS_TOKEN,
    // Use 'sandbox' if you're using the Polar Sandbox environment
    // Remember that access tokens, products, etc. are completely separated between environments.
    // Access tokens obtained in Production are for instance not usable in the Sandbox environment.
    server: 'production'
});

const auth = betterAuth({
    // ... Better Auth config
    plugins: [
        polar({
            client,
            // Enable automatic Polar Customer creation on signup
            createCustomerOnSignUp: true,
            // Enable customer portal
            enableCustomerPortal: true, // Deployed under /portal for authenticated users
            // Configure checkout
            checkout: {
                enabled: true,
                products: [
                    {
                        productId: "123-456-789", // ID of Product from Polar Dashboard
                        slug: "pro" // Custom slug for easy reference in Checkout URL, e.g. /checkout/pro
                    }
                ],
                successUrl: "/success?checkout_id={CHECKOUT_ID}"
            },
            // Incoming Webhooks handler will be installed at /polar/webhooks
            webhooks: {
                secret: process.env.POLAR_WEBHOOK_SECRET,
                onPayload: ...,
            }
        })
    ]
});
  1. You need to trigger some type of error from Polar. You can do this by doing either of these:
  • Attempt to sign up with an email address that doesn't exist (since polar is checking if they're real) like name@sdfsdfdsf.com so it triggers a validation error from Polar.
  • Enter an invalid POLAR_ACCESS_TOKEN in your .env
  1. Sign up in your application
  2. Check your database to confirm if the user was created (it should, thats the bug here)

Current vs. Expected behavior

Currently, better auth creates the user in the local database when there is an error from Polar during automatic customer creation.

I would expect it not to create the user in the database to ensure polar and better-auth stay in sync.

What version of Better Auth are you using?

1.2.6

Provide environment information

os: macos
browser: brave
NextJS 15.3.1-canary.7

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

Backend, Package

Additional context

No response

Originally created by @proevilz on GitHub (Apr 13, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Follow the tutorial on how to setup Polar with Better Auth. ```Typescript import { betterAuth } from "better-auth"; import { polar } from "@polar-sh/better-auth"; import { Polar } from "@polar-sh/sdk"; const client = new Polar({ accessToken: process.env.POLAR_ACCESS_TOKEN, // Use 'sandbox' if you're using the Polar Sandbox environment // Remember that access tokens, products, etc. are completely separated between environments. // Access tokens obtained in Production are for instance not usable in the Sandbox environment. server: 'production' }); const auth = betterAuth({ // ... Better Auth config plugins: [ polar({ client, // Enable automatic Polar Customer creation on signup createCustomerOnSignUp: true, // Enable customer portal enableCustomerPortal: true, // Deployed under /portal for authenticated users // Configure checkout checkout: { enabled: true, products: [ { productId: "123-456-789", // ID of Product from Polar Dashboard slug: "pro" // Custom slug for easy reference in Checkout URL, e.g. /checkout/pro } ], successUrl: "/success?checkout_id={CHECKOUT_ID}" }, // Incoming Webhooks handler will be installed at /polar/webhooks webhooks: { secret: process.env.POLAR_WEBHOOK_SECRET, onPayload: ..., } }) ] }); ``` 1) You need to trigger some type of error from Polar. You can do this by doing either of these: - Attempt to sign up with an email address that doesn't exist (since polar is checking if they're real) like `name@sdfsdfdsf.com` so it triggers a validation error from Polar. - Enter an invalid `POLAR_ACCESS_TOKEN` in your `.env` 2) Sign up in your application 3) Check your database to confirm if the user was created (it should, thats the bug here) ### Current vs. Expected behavior Currently, better auth creates the user in the local database when there is an error from Polar during automatic customer creation. I would expect it not to create the user in the database to ensure polar and better-auth stay in sync. ### What version of Better Auth are you using? 1.2.6 ### Provide environment information ```bash os: macos browser: brave NextJS 15.3.1-canary.7 ``` ### Which area(s) are affected? (Select all that apply) Backend, Package ### Additional context _No response_
Author
Owner

@proevilz commented on GitHub (Apr 13, 2025):

Created an issue here too https://github.com/polarsource/polar-adapters/issues/182

@proevilz commented on GitHub (Apr 13, 2025): Created an issue here too https://github.com/polarsource/polar-adapters/issues/182
Author
Owner

@Bekacru commented on GitHub (Apr 13, 2025):

The Polar customer is created after the user is registered on the Better Auth side. A failure in customer creation shouldn't block user registration in general. But, for specific use cases the Polar plugin can support an option to delete the user if customer creation fails.

@Bekacru commented on GitHub (Apr 13, 2025): The Polar customer is created after the user is registered on the Better Auth side. A failure in customer creation shouldn't block user registration in general. But, for specific use cases the Polar plugin can support an option to delete the user if customer creation fails.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1033