Additional fields for organizationRole table
Pass additionalFields configuration to organization plugin under schema.organizationRole to add custom fields (e.g., color with type 'string' and defaultValue '#ffffff'). On client, use inferOrgAdditionalFields or pass schema values directly.
Team database table schema
The team table contains: id (string, primary key, unique identifier for each team), name (string, name of the team), organizationId (string, foreign key referencing organization.id), createdAt (Date, timestamp of team creation), updatedAt (Date, optional, timestamp of last update).
TeamMember database table schema
The teamMember table contains: id (string, primary key, unique identifier for each team member), teamId (string, foreign key referencing team.id), userId (string, foreign key referencing user.id), createdAt (Date, optional, timestamp of team member creation).
Organization table database schema
The organization table contains: id (string, primary key, unique identifier for each organization), name (string, name of the organization), slug (string, unique slug of the organization), logo (string, optional, logo of the organization), metadata (string, optional, additional metadata for the organization), createdAt (Date, timestamp of organization creation).
Member table database schema
The member table contains: id (string, primary key, unique identifier for each member), userId (string, foreign key referencing user.id), organizationId (string, foreign key referencing organization.id), role (string, role of the user in the organization), createdAt (Date, timestamp of when member was added to organization).
Invitation table database schema
The invitation table contains: id (string, primary key, unique identifier for each invitation), email (string, email address of the user), inviterId (string, foreign key referencing user.id), organizationId (string, foreign key referencing organization.id), role (string, optional, role of the user in the organization), status (string, status of the invitation), createdAt (Date, timestamp of invitation creation), expiresAt (Date, timestamp of when invitation expires). When teams are enabled, an optional teamId field (string, foreign key referencing team.id) is added.
Session table organization fields
Two fields are added to the session table: activeOrganizationId (string, optional, ID of the active organization), activeTeamId (string, optional, ID of the active team).
OrganizationRole table database schema
The optional organizationRole table contains: id (string, unique identifier for each organization role), organizationId (string, foreign key referencing organization.id), role (string, name of the role), permission (string, permission of the role), createdAt (Date, timestamp of role creation), updatedAt (Date, optional, timestamp of last update).
Organization plugin schema customization
The organization plugin accepts a schema option to customize table names and fields. You can map table names using modelName (e.g., map 'organization' to 'organizations'), map existing fields (e.g., map 'name' to 'title'), and add additional fields using additionalFields with properties including type, input, and required.
Additional fields in organization plugin schema
Starting with Better Auth v1.3, custom fields can be added to organization, invitation, member, and team tables. When additional fields are added to a model, the relevant API endpoints automatically accept and return these new properties in request and response payloads.
Additional field configuration format
When adding additional fields to organization plugin schema models, each field requires: type (string specifying the field type), input (boolean indicating if field accepts input), required (boolean indicating if field is mandatory).
inferOrgAdditionalFields function with auth type
The inferOrgAdditionalFields function can be used in the client to infer additional fields from the auth object type by passing the auth type as a generic parameter: inferOrgAdditionalFields<typeof auth>(). This enables type-safe inference of custom fields defined on the server.
inferOrgAdditionalFields function without auth type
If the auth object type cannot be imported in the client, inferOrgAdditionalFields can be called without a generic parameter, instead passing a schema object with the organization.additionalFields configuration to infer custom fields.