polar
polar copied to clipboard
Checkout via productId fails with VALIDATION_ERROR while slug-based checkout works as expected
Description
i followed the steps of implementing polar with better-auth. i found an issue when getting the checkout session for a specific product.. here is my code
// lib/better-ath/auth.ts
import {
betterAuth
} from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';
import prisma from '../prisma';
import { polar as baPolar } from "@polar-sh/better-auth";
import { polar } from '../polar';
export const auth = betterAuth({
appName: "better_auth_nextjs_demo",
database: prismaAdapter(prisma, {
provider: "postgresql"
}),
emailAndPassword: {
enabled: true,
autoSignIn: true,
minPasswordLength: 8,
maxPasswordLength: 20,
},
plugins: [
baPolar({
client: polar,
// 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: "4b3ba69c-1355-4b9d-8639-215ec7a291ef", // ID of Product from Polar Dashboard
slug: "demo-pro" // Custom slug for easy reference in Checkout URL, e.g. /checkout/pro
}
],
successUrl: "/confirmation?checkoutId={CHECKOUT_ID}"
},
})
]
});
better-auth api code :
// /app/api/auth/[...all]/route.ts
import { auth } from "@/lib/better-auth/auth"; // path to your auth file
import { toNextJsHandler } from "better-auth/next-js";
export const { POST, GET } = toNextJsHandler(auth);
when i access /api/auth/checkout?productId=PRODUCT_ID
i receive error {"code":"VALIDATION_ERROR","message":"Invalid query parameters"}
But when i use the slug method
and access /api/auth/checkout/PRODUCT_SLUG if return the checkout page correctly
Current Behavior
Can't access the checkout page when using the Checkouts with product id method
Expected Behavior
It should work like when using the Checkouts with product slug method as mentioned in the documentation here
Screenshots
Environment:
- Operating System: Linux (Ubuntu 24.04.2 LTS)
- Browser (if applicable): Chrome (Version 132.0.6834.159 (Official Build) (64-bit))