Add billing to your Better Auth setup without touching the Commet SDK directly. Your authClient now handles everything.
What's New
We shipped @commet/better-auth - a plugin that extends Better Auth with billing primitives.
Your authClient now handles:
- Customer sync (automatic on signup)
- Subscription management
- Feature flags
- Usage tracking
- Seat management
- Customer portal access
No separate SDK initialization. No manual customer mapping. The plugin automatically syncs your auth users with Commet customers.
How It Works
Install the Plugin
// src/lib/auth.ts
import { betterAuth } from 'better-auth'
import { commet } from '@commet/better-auth'
export const auth = betterAuth({
plugins: [
commet({
apiKey: process.env.COMMET_API_KEY!,
environment: 'sandbox'
})
]
})Use It Everywhere
import { authClient } from '@/lib/auth-client'
// Check feature access
const { allowed } = await authClient.features.canUse('api_access')
// Track usage
await authClient.usage.track('api_call')
// Manage seats
await authClient.seats.add('team_member', 1)
// Get subscription
const sub = await authClient.subscription.get()
// Open customer portal
const { url } = await authClient.customer.portal()Why This Matters
With the plugin, you don't need to manually sync user states between your auth system and billing system.
Before
// Get user from auth
const session = await getSession()
// Map to billing customer
const customer = await findCustomer(session.user.id)
// Check billing state
const sub = await commet.subscriptions.get({
externalId: customer.externalId
})
// Gate feature
if (sub.status !== 'active') redirect('/upgrade')After
const { allowed } = await authClient.features.canUse('api_access')
if (!allowed) redirect('/upgrade')Template
We have complete reference implementations in our templates showing how to implement the plugin with different billing models. Run commet create to get started.
Conclusion
If you're using Better Auth, this is the fastest way to add billing. Check out our Better Auth documentation for more details.
If you have any questions, please reach out to us and we'll be happy to help.