Skip to main content

Better Auth

Better Auth adapter tables (camelCase) and the link to platform users.
2 min read

Sources: 000002_better_auth.up.sql, extended by 000026_legal_acceptance.up.sql and 000061_better_auth_account_issuer.up.sql.

Warning

Tables distinct from users. Link: users.auth_user_id → "user".id.

"user"#

ColumnTypeNotes
idTEXT PKAuth id
nameTEXT NOT NULL
emailTEXT NOT NULLUnique
emailVerifiedBOOLEANDefault false
imageTEXT
stripeCustomerIdTEXTBilling plugin
termsAcceptedAtTIMESTAMPTZAcceptance date on accounts created since the current legal version
termsVersionTEXTAccepted Terms version
privacyNoticeVersionTEXTVersion of the privacy notice presented and accepted
createdAt / updatedAtTIMESTAMPTZ

Legal fields are assigned server-side when creating an account and are not exposed as client input fields. Accounts from before the migration stay NULL: no retroactive acceptance is recorded that did not happen.

session#

ColumnTypeNotes
idTEXT PK
expiresAtTIMESTAMPTZ
tokenTEXT NOT NULLUnique; used in Authorization: Bearer
ipAddress / userAgentTEXT
userIdTEXT → userCASCADE delete
createdAt / updatedAtTIMESTAMPTZ

Go resolves the session with a lookup by token and expiresAt > now().

account#

Provider accounts (OAuth / credentials):

ColumnNotes
issuerRequired. Credential accounts use local:credential. OAuth uses the provider issuer (Google: https://accounts.google.com) or local:oauth:<providerId>. Unique with accountId.
accountId / providerIdProvider identity. For email/password, accountId equals "user".id.
userIdOwner
accessToken / refreshToken / idTokenSecrets
accessTokenExpiresAt / refreshTokenExpiresAt
scope / password
timestamps

verification#

Email/OTP verification tokens: identifier, value, expiresAt.

subscription#

Subscriptions from the Better Auth / Stripe plugin:

ColumnNotes
plan / referenceIdPlan and reference (e.g. org/profile)
stripeCustomerId / stripeSubscriptionId
statusDefault incomplete
periodStart / periodEnd
trialStart / trialEnd
cancelAtPeriodEnd / cancelAt / canceledAt / endedAt
seats / billingInterval
stripeScheduleId

Usage rules#

  • Do not mutate these tables from product-domain GORM.
  • Login/session = Better Auth API (/api/auth/* in Next).
  • The product uses users.id after the identity mirror.