Versions in this module Expand all Collapse all v1 v1.0.2 Aug 9, 2026 Changes in this version + var ErrInvalidPlaceholderEmail = errors.New("betterauth: invalid placeholder email") + func CreatePlaceholderEmail(options PlaceholderEmailOptions) (string, error) + type PlaceholderEmailOptions struct + Identifier string + Namespace string v1.0.1 Jul 29, 2026 Changes in this version + var ErrNoSession = errors.New("betterauth: no session") type Server + func (s *Server) ResolveSession(ctx context.Context, r *http.Request) (SessionResult, error) + type SessionResult struct + Session Session + User User v1.0.0 Jul 29, 2026 Changes in this version + const APIVersion + const AuditImpersonationStart + const AuditImpersonationStop + const EventUserCreated + const ModelAccount + const ModelAuditEvent + const ModelOutboxEvent + const ModelSession + const ModelUser + const ModelVerification + const ProviderGoogle + const PurposeEmailChange + const PurposeEmailChangeConfirmation + const PurposeEmailVerify + const PurposeOAuthState + const PurposePasswordReset + const PurposeUserDeletion + const Version + var ErrAccountNotLinked = errors.New("betterauth: account not linked") + var ErrConflict = errors.New("betterauth: conflict") + var ErrNotFound = errors.New("betterauth: not found") + var ErrReplay = errors.New("betterauth: replay") + var ErrSignUpDisabled = errors.New("betterauth: oauth sign up disabled") + func HashToken(raw string) string + type AESGCMTokenCipher struct + func NewAESGCMTokenCipher(key []byte) (*AESGCMTokenCipher, error) + func (c *AESGCMTokenCipher) Open(_ context.Context, encoded string) (string, error) + func (c *AESGCMTokenCipher) Seal(_ context.Context, plaintext string) (string, error) + type AccountManagementConfig struct + AllowLinkingDifferentEmails bool + AllowUnlinkingAll bool + DisableImplicitLinking bool + LinkingEnabled *bool + RequireLocalEmailVerified *bool + TrustedProviderResolver TrustedProviderResolver + TrustedProviders []string + UpdateAccountOnSignIn *bool + UpdateUserInfoOnLink bool + type AdapterCapabilities struct + Arrays bool + Booleans bool + Dates bool + JSON bool + Joins bool + NumericIDs bool + Transactions bool + UUIDs bool + type AdminConfig struct + AdminRoles []string + AdminUserIDs []string + AllowImpersonatingAdmins bool + DefaultRole string + RoleResolver AdminRoleResolver + type AdminRoleResolver interface + Roles func(context.Context, User) ([]string, error) + type Argon2Params struct + Iterations uint32 + KeyLength uint32 + Memory uint32 + Parallelism uint8 + SaltLength uint32 + func DefaultArgon2Params() Argon2Params + type Argon2idVerifier struct + MaxPassword int + Params Argon2Params + func NewArgon2idVerifier(params Argon2Params, maxPassword int) (*Argon2idVerifier, error) + func (v *Argon2idVerifier) Hash(_ context.Context, password string) (string, error) + func (v *Argon2idVerifier) Verify(ctx context.Context, encoded, password string) (PasswordVerification, error) + type AuditEvent struct + Action string + ActorUserID string + Details map[string]string + ID string + OccurredAt time.Time + Request RequestMetadata + SchemaVersion int + SessionID string + SubjectUserID string + type BackgroundTask func(context.Context) error + type BackgroundTaskRunner interface + Submit func(context.Context, BackgroundTask) error + type ChangePasswordParams struct + CurrentTokenHash string + PreviousHash string + ReplacementHash string + ReplacementSession Session + RevokeOtherSessions bool + UserID string + type Clock interface + Now func() time.Time + type Config struct + Account AccountManagementConfig + Admin AdminConfig + AllowedRedirectURLs []string + BackgroundTasks BackgroundTaskRunner + BasePath string + Clock Clock + Cookie CookieConfig + Database DatabaseAdapter + DeleteUserTTL time.Duration + EmailPassword EmailPasswordConfig + EmailVerification EmailVerificationConfig + EmailVerificationTTL time.Duration + Hooks ServerHooks + ImpersonationAuthorizer ImpersonationAuthorizer + ImpersonationDuration time.Duration + Mailer Mailer + MaxPasswordBytes int + MaxRequestBytes int64 + MaxResponseBytes int64 + MinPasswordBytes int + OAuthStateTTL time.Duration + PasswordResetTTL time.Duration + Passwords PasswordVerifier + Plugins []Plugin + ProviderTimeout time.Duration + ProviderTokenCipher TokenCipher + PublicURL string + RateLimiter RateLimiter + Schema Schema + SessionDuration time.Duration + SessionFreshAge time.Duration + SocialProviders map[string]OAuthProvider + Tokens TokenSource + TrustProxyHeaders bool + TrustedOriginResolver TrustedOriginResolver + TrustedOrigins []string + User UserManagementConfig + type CookieConfig struct + CSRFName string + Name string + Path string + SameSite http.SameSite + type CountQuery struct + Model string + Where []Where + type CreateEmailUserParams struct + CreateSession bool + Event DomainEvent + PasswordHash string + Session Session + User User + type CreateQuery struct + Data Record + ForceAllowID bool + Model string + Select []string + type CryptoTokenSource struct + func (CryptoTokenSource) Token(byteLength int) (string, error) + type DatabaseAdapter interface + Capabilities func() AdapterCapabilities + ConsumeOne func(context.Context, DeleteQuery) (Record, error) + Count func(context.Context, CountQuery) (int64, error) + Create func(context.Context, CreateQuery) (Record, error) + Delete func(context.Context, DeleteQuery) error + DeleteMany func(context.Context, DeleteQuery) (int64, error) + FindMany func(context.Context, FindManyQuery) ([]Record, error) + FindOne func(context.Context, FindOneQuery) (Record, error) + ID func() string + IncrementOne func(context.Context, IncrementQuery) (Record, error) + Transaction func(context.Context, func(DatabaseAdapter) error) error + Update func(context.Context, UpdateQuery) (Record, error) + UpdateMany func(context.Context, UpdateQuery) (int64, error) + func WrapDatabaseAdapter(inner DatabaseAdapter, schema Schema) (DatabaseAdapter, error) + type DatabaseHook struct + After DatabaseHookHandler + Before DatabaseHookHandler + Model string + Operations []DatabaseOperation + type DatabaseHookContext struct + Count int64 + Data Record + Increment map[string]float64 + Model string + Operation DatabaseOperation + Result Record + Where []Where + type DatabaseHookHandler func(context.Context, *DatabaseHookContext) error + type DatabaseOperation string + const DatabaseConsumeOne + const DatabaseCreate + const DatabaseDelete + const DatabaseDeleteMany + const DatabaseIncrementOne + const DatabaseUpdate + const DatabaseUpdateMany + type DeleteQuery struct + Model string + Where []Where + type DomainEvent struct + AggregateID string + ID string + Name string + OccurredAt time.Time + Payload map[string]string + SchemaVersion int + type EmailPasswordConfig struct + AutoSignIn *bool + CustomSyntheticUser SyntheticUserFactory + DisableSignUp bool + OnExistingUserSignUp UserLifecycleHook + OnPasswordReset UserLifecycleHook + RequireEmailVerification bool + RevokeSessionsOnPasswordReset bool + type EmailVerificationConfig struct + AfterVerification UserLifecycleHook + AutoSignInAfterVerification bool + BeforeVerification UserLifecycleHook + SendOnSignIn bool + SendOnSignUp *bool + type EndpointValidator interface + Validate func(any) error + type EndpointValidatorFunc func(any) error + func (validator EndpointValidatorFunc) Validate(value any) error + type Error struct + Code ErrorCode + Message string + RequestID string + RetryAfter time.Duration + Status int + func NewError(code ErrorCode, message string, status int, cause error) *Error + func (e *Error) Error() string + func (e *Error) Unwrap() error + type ErrorCode string + const CodeAccountLinkedElsewhere + const CodeAccountNotFound + const CodeAccountNotLinked + const CodeBadRequest + const CodeCannotImpersonateAdmins + const CodeCannotImpersonateUsers + const CodeConflict + const CodeCredentialNotFound + const CodeEmailAlreadyVerified + const CodeEmailMismatch + const CodeEmailNotVerified + const CodeFailedRefreshToken + const CodeForbidden + const CodeInternal + const CodeInvalidCSRF + const CodeInvalidCredentials + const CodeInvalidEmail + const CodeInvalidOrigin + const CodeInvalidPassword + const CodeInvalidToken + const CodeLinkingDifferentEmails + const CodeLinkingNotAllowed + const CodeMethodNotAllowed + const CodeNotFound + const CodeOAuthSignUpDisabled + const CodePasswordTooLong + const CodePasswordTooShort + const CodeProviderFailure + const CodeProviderNotSupported + const CodeRateLimited + const CodeRefreshTokenNotFound + const CodeSessionNotFresh + const CodeSignUpDisabled + const CodeTokenRefreshUnsupported + const CodeUnauthorized + const CodeUnlinkLastAccount + const CodeUserAlreadyExists + const CodeValidation + type EventHandler interface + HandleEvent func(context.Context, DomainEvent) error + type FieldSchema struct + FieldName string + Index bool + Input bool + References string + Required bool + Returned bool + Type FieldType + Unique bool + type FieldType string + const FieldBoolean + const FieldDate + const FieldJSON + const FieldNumber + const FieldString + const FieldStringArray + type FieldValidation struct + Enum []string + Kind ValidationKind + MaxLength int + MinLength int + Nullable bool + Required bool + type FindManyQuery struct + Joins []Join + Limit int + Model string + Offset int + Select []string + Sort *Sort + Where []Where + type FindOneQuery struct + Joins []Join + Model string + Select []string + Where []Where + type HookContext struct + AuthenticateOAuth func(OAuthProfile, ProviderTokens) (*IssuedSession, bool, error) + BackgroundTasks BackgroundTaskRunner + BaseURL string + Body any + Clock Clock + Context context.Context + Cookies CookieConfig + Database DatabaseAdapter + Failure error + GenerateID func() (string, error) + GenerateToken func(int) (string, error) + Headers http.Header + IsTrustedOrigin func(string) bool + IssueSession func(string) (*IssuedSession, error) + Params map[string]string + Passwords PasswordVerifier + Path string + PluginID string + Query url.Values + RawBody []byte + Request *http.Request + Response *PluginResponse + Schema Schema + Session *Session + SessionFreshAge time.Duration + TrustedOrigins []string + User *User + ValidateCSRF func() error + func (ctx *HookContext) RunInBackground(task BackgroundTask) error + type HookMatcher func(*HookContext) bool + type ImpersonationAuthorizer interface + CanImpersonate func(context.Context, User, User) error + type IncrementQuery struct + Increment map[string]float64 + Model string + Set Record + Where []Where + type IndexSchema struct + Fields []string + Name string + Unique bool + type InlineBackgroundTasks struct + func (InlineBackgroundTasks) Submit(ctx context.Context, task BackgroundTask) error + type IssuedSession struct + Session Session + User User + func (issued *IssuedSession) Apply(response *PluginResponse) error + type Join struct + From string + Limit int + Model string + Relation JoinRelation + To string + type JoinRelation string + const JoinManyToMany + const JoinOneToMany + const JoinOneToOne + type Mail struct + ActionURL string + ExpiresAt time.Time + Kind string + To string + Token string + type Mailer interface + Send func(context.Context, Mail) error + type ModelSchema struct + Fields map[string]FieldSchema + Indexes []IndexSchema + ModelName string + type NopRateLimiter struct + func (NopRateLimiter) Allow(context.Context, RateLimitRequest) (RateLimitDecision, error) + type OAuthAccount struct + CreatedAt time.Time + ID string + Provider string + ProviderAccountID string + Scope string + UpdatedAt time.Time + UserID string + type OAuthProfile struct + Email string + EmailVerified bool + ImageURL string + Name string + Provider string + ProviderAccountID string + type OAuthProvider interface + AuthorizationURL func(state, codeChallenge, nonce, redirectURI string) (string, error) + Exchange func(context.Context, string, string, string, string) (OAuthResult, error) + type OAuthProviderSignUpPolicy interface + DisableImplicitSignUp func() bool + DisableSignUp func() bool + type OAuthResult struct + Profile OAuthProfile + Tokens ProviderTokens + type OAuthState struct + CreatedAt time.Time + ErrorReturnTo string + ExpiresAt time.Time + Hash string + ID string + LinkUserID string + NewUserReturnTo string + Nonce string + PKCEVerifier string + RedirectURI string + RequestSignUp bool + ReturnTo string + type OAuthTokenRefresher interface + Refresh func(context.Context, string) (ProviderTokens, error) + type OAuthUpsertPolicy struct + AllowImplicitLink bool + AllowSignUp bool + RequireLocalVerification bool + UpdateAccountOnSignIn bool + UpdateUserInfoOnLink bool + type ObjectValidator struct + AllowUnknown bool + Fields map[string]FieldValidation + func (validator ObjectValidator) Validate(value any) error + func (validator ObjectValidator) ValidateConfiguration() error + type OneTimePurpose string + type OneTimeToken struct + CreatedAt time.Time + ExpiresAt time.Time + Hash string + ID string + Metadata map[string]string + Purpose OneTimePurpose + UserID string + type OutboxDispatcher struct + BatchSize int + Clock Clock + Database DatabaseAdapter + Handler EventHandler + func (dispatcher OutboxDispatcher) RunOnce(ctx context.Context) (int, error) + type PasswordCredential struct + PasswordHash string + UpdatedAt time.Time + UserID string + type PasswordVerification struct + ReplacementHash string + Valid bool + type PasswordVerifier interface + Hash func(context.Context, string) (string, error) + Verify func(context.Context, string, string) (PasswordVerification, error) + type Plugin struct + After []PluginAfterHook + Before []PluginBeforeHook + DatabaseHooks []DatabaseHook + Dependencies []string + Endpoints []PluginEndpoint + ID string + Init PluginInit + Middlewares []PluginMiddleware + OnRequest RequestHook + OnResponse ResponseHook + RateLimits []PluginRateLimitRule + Schema Schema + TrustedOrigins []string + type PluginAfterHook struct + Handler ResponseHook + Matcher HookMatcher + type PluginBeforeHook struct + Handler RequestHook + Matcher HookMatcher + type PluginEndpoint struct + AllowNonKebabPath bool + BodyValidator EndpointValidator + Handler PluginEndpointHandler + Method string + Name string + Path string + QueryValidator EndpointValidator + SkipOriginCheck bool + Use []RequestHook + type PluginEndpointHandler func(*HookContext) (*PluginResponse, error) + type PluginInit func(PluginInitContext) (PluginInitResult, error) + type PluginInitContext struct + BaseURL string + Database DatabaseAdapter + PluginID string + Schema Schema + TrustedOrigins []string + type PluginInitResult struct + Schema Schema + TrustedOrigins []string + type PluginMiddleware struct + Handler RequestHook + Matcher HookMatcher + type PluginRateLimitRule struct + AccountKey func(*HookContext) string + Action string + Matcher HookMatcher + Max int + Window time.Duration + type PluginResponse struct + Body []byte + Headers http.Header + Status int + func CSRFMiddleware(context *HookContext) (*PluginResponse, error) + func FreshSessionMiddleware(context *HookContext) (*PluginResponse, error) + func JSONResponse(status int, value any) (*PluginResponse, error) + func SessionMiddleware(context *HookContext) (*PluginResponse, error) + func (response *PluginResponse) DecodeJSON(dst any) error + func (response *PluginResponse) SetCookie(cookie *http.Cookie) error + func (response *PluginResponse) SetJSON(value any) error + type ProviderTokens struct + AccessToken string + AccessTokenExpiresAt time.Time + IDToken string + RefreshToken string + RefreshTokenExpiresAt time.Time + Scope string + type RateLimitDecision struct + Allowed bool + RetryAfter time.Duration + type RateLimitRequest struct + AccountKey string + Action string + IP string + Max int + Window time.Duration + type RateLimiter interface + Allow func(context.Context, RateLimitRequest) (RateLimitDecision, error) + type Record map[string]any + type RequestHook func(*HookContext) (*PluginResponse, error) + func RequireResourceOwnership(config ResourceOwnershipConfig) (RequestHook, error) + type RequestMetadata struct + IP string + RequestID string + UserAgent string + type ResourceIDSource string + const ResourceIDBody + const ResourceIDParams + const ResourceIDQuery + type ResourceOwnershipConfig struct + IDField string + IDParam string + IDSource ResourceIDSource + Model string + OwnerField string + type ResponseHook func(*HookContext, *PluginResponse) error + type Schema map[string]ModelSchema + func CoreSchema() Schema + func MergeSchema(base Schema, extensions ...Schema) (Schema, error) + type SchemaConfigurableAdapter interface + WithSchema func(Schema) (DatabaseAdapter, error) + type Server struct + func New(cfg Config) (*Server, error) + func (s *Server) Handler() http.Handler + func (s *Server) Schema() Schema + func (s *Server) SetPassword(ctx context.Context, userID, password string) error + func (s *Server) VerifyPassword(ctx context.Context, userID, password string) (bool, error) + type ServerHooks struct + After []PluginAfterHook + Before []PluginBeforeHook + OnRequest RequestHook + OnResponse ResponseHook + type Session struct + CreatedAt time.Time + ExpiresAt time.Time + ID string + ImpersonationID string + ImpersonatorID string + LastSeenAt time.Time + RevokedAt *time.Time + TokenHash string + UpdatedAt time.Time + UserID string + type Sort struct + Direction string + Field string + type StoredOAuthAccount struct + Account OAuthAccount + Tokens ProviderTokens + type StringMode string + const StringInsensitive + const StringSensitive + type SyntheticUserFactory func(SyntheticUserInput) Record + type SyntheticUserInput struct + AdditionalFields Record + CoreFields Record + ID string + type TokenCipher interface + Open func(context.Context, string) (string, error) + Seal func(context.Context, string) (string, error) + type TokenSource interface + Token func(byteLength int) (string, error) + type TrustedOriginResolver interface + TrustedOrigins func(context.Context, *http.Request) ([]string, error) + type TrustedOriginResolverFunc func(context.Context, *http.Request) ([]string, error) + func (resolver TrustedOriginResolverFunc) TrustedOrigins(ctx context.Context, request *http.Request) ([]string, error) + type TrustedProviderResolver interface + TrustedProviders func(context.Context, *http.Request) ([]string, error) + type TrustedProviderResolverFunc func(context.Context, *http.Request) ([]string, error) + func (resolver TrustedProviderResolverFunc) TrustedProviders(ctx context.Context, request *http.Request) ([]string, error) + type UpdateQuery struct + Model string + Update Record + Where []Where + type User struct + CreatedAt time.Time + DisabledAt *time.Time + Email string + EmailVerified bool + ID string + ImageURL string + Name string + UpdatedAt time.Time + func (user User) MarshalJSON() ([]byte, error) + type UserDeletionHook func(context.Context, User) error + type UserLifecycleHook func(context.Context, User) error + type UserManagementConfig struct + AfterDelete UserDeletionHook + BeforeDelete UserDeletionHook + ChangeEmailEnabled bool + DeleteUserEnabled bool + SendChangeEmailConfirmation bool + SendDeleteAccountVerification bool + UpdateEmailWithoutVerification bool + type ValidationKind string + const ValidationArray + const ValidationBoolean + const ValidationInteger + const ValidationNumber + const ValidationObject + const ValidationString + type Where struct + Connector WhereConnector + Field string + Mode StringMode + Operator WhereOperator + Value any + func Eq(field string, value any) Where + func ValidateWhere(where []Where, allowEmpty bool) ([]Where, error) + type WhereConnector string + const WhereAND + const WhereOR + type WhereOperator string + const WhereContains + const WhereEQ + const WhereEndsWith + const WhereGT + const WhereGTE + const WhereIn + const WhereLT + const WhereLTE + const WhereNE + const WhereNotIn + const WhereStartsWith v1.0.0-rc.1 Jul 29, 2026