Connect multiple authentication methods
A user signs in with email/password and later adds Google or another OAuth provider.
Better Auth · Pipe
An account is Better Auth’s record for an authentication method connected to a user. Account records support multiple providers, account listing, linking, unlinking, and account-specific provider operations.
The account configuration controls how Better Auth models and stores linked authentication methods. It can encrypt OAuth tokens and govern whether accounts may be linked, which providers are trusted for linking, and whether different email addresses are allowed.
betterAuth({ account: { ... } })| Name | Type | Description |
|---|---|---|
account | object | Account configuration object; documented options include modelName, fields, encryptOAuthTokens, storeStateStrategy, storeAccountCookie, and accountLinking. |
An account configuration that controls authentication-method records, OAuth-token storage, account cookies, and account-linking behavior.
accountId.listAccounts returns all authentication methods associated with the signed-in user.import { betterAuth } from "better-auth";
export const auth = betterAuth({
account: {
encryptOAuthTokens: true,
accountLinking: {
enabled: true,
trustedProviders: ["google", "github", "email-password"],
allowDifferentEmails: false,
},
},
});Configures account storage behavior, OAuth-token encryption, and account-linking rules.
A user signs in with email/password and later adds Google or another OAuth provider.
An application must show or remove the providers currently connected to a user.
A provider returns OAuth tokens that should not be stored in plaintext.
A product needs strict rules about which providers may be linked.
An account represents one authentication method connected to a user. Its Better Auth record id is the account identifier used by account-management APIs, while the provider identity is represented by the providerId and provider-assigned accountId.
Follow-up: Why should an application retain the Better Auth record ID? Because unlinking and account-specific APIs require that record ID rather than the external provider subject identifier.
Account linking is enabled by default. Users can associate additional social or OAuth methods when the provider confirms the email as verified; configuration can restrict trusted providers and whether different emails are accepted.
Follow-up: How would you prevent an untrusted provider from linking? Configure accountLinking.trustedProviders with only the permitted provider identifiers.
encryptOAuthTokens: true encrypts OAuth tokens before they are stored in the database. For providers with large JWTs or production flows needing durable token storage, the documentation recommends database-backed storage.
Follow-up: What trade-off applies to cookie-based account storage? Large cookies may still hit browser or proxy cookie/header limits despite Better Auth chunking them.
listAccountslinkAccountgetAccessTokenrefreshTokenaccountInfoaccountLinkingencryptOAuthTokensstoreAccountCookie