Purchase
Authentication and Customers
Start with app authentication, then map signed-in users to Purchase customers.
Purchase does not replace application auth. The example begins with normal sign-in and sign-up pages, then maps authenticated users into billing customers.
Relevant files:
Auth flow
The client form uses Better Auth:
const result =
props.mode === "sign-up"
? await authClient.signUp.email({
email,
password,
name,
callbackURL: "/workspace"
})
: await authClient.signIn.email({
email,
password,
callbackURL: "/workspace"
})Session to customer mapping
The key idea is that billing starts from app identity, not provider identity.
The example converts the session into an app-owned customer shape with sessionUser(...), then passes that user into Purchase runtime helpers.
Why this matters
This keeps:
- auth ownership in the app
- customer ids stable across providers
- commercial state aligned with the rest of product state