Skip to main content

Module entity

Module entity 

Source
Expand description

Entity traits for the Better Auth framework.

These traits define the interface that entity types must implement. The framework accesses entity fields through these trait methods, allowing users to define their own entity structs with custom field names and extra fields.

Use #[derive(AuthUser)] etc. from better-auth-derive to auto-implement these traits, or implement them manually.

§Meta traits

Each entity trait has a corresponding Auth*Meta trait (e.g., AuthUserMeta) that provides table and column name mappings for SQL generation. The derive macros automatically implement both the entity trait and the meta trait.

If you implement entity traits manually (without derive macros), you must also implement the corresponding Auth*Meta trait. An empty impl block is sufficient to get the default column/table names:

impl AuthUserMeta for MyUser {}   // uses default column names
impl AuthSessionMeta for MySession {}

Structs§

MemberUserView
Minimal user info for member-related API responses.

Constants§

PASSWORD_HASH_KEY
Metadata key used to store the password hash inside AuthUser::metadata().

Traits§

AuthAccount
Trait representing an account entity (OAuth provider linking).
AuthAccountMeta
SQL column/table metadata for AuthAccount entities.
AuthApiKey
Trait representing an API key entity.
AuthApiKeyMeta
SQL column/table metadata for AuthApiKey entities.
AuthInvitation
Trait representing an invitation entity.
AuthInvitationMeta
SQL column/table metadata for AuthInvitation entities.
AuthMember
Trait representing an organization member entity.
AuthMemberMeta
SQL column/table metadata for AuthMember entities.
AuthOrganization
Trait representing an organization entity.
AuthOrganizationMeta
SQL column/table metadata for AuthOrganization entities.
AuthPasskey
Trait representing a passkey entity.
AuthPasskeyMeta
SQL column/table metadata for AuthPasskey entities.
AuthSession
Trait representing a session entity.
AuthSessionMeta
SQL column/table metadata for AuthSession entities.
AuthTwoFactor
Trait representing a two-factor authentication entity.
AuthTwoFactorMeta
SQL column/table metadata for AuthTwoFactor entities.
AuthUser
Trait representing a user entity.
AuthUserMeta
SQL column/table metadata for AuthUser entities.
AuthVerification
Trait representing a verification token entity.
AuthVerificationMeta
SQL column/table metadata for AuthVerification entities.