Documentation
¶
Overview ¶
Package organization provides Better Auth-shaped multi-tenant organization management and authorization.
Index ¶
- Constants
- func New(config Config) (betterauth.Plugin, error)
- type AddMemberInput
- type Config
- type FullOrganization
- type Hooks
- type Invitation
- type InvitationDelivery
- type Manager
- type Member
- type MutationEvent
- type Organization
- type OrganizationRole
- type Permission
- type Role
- type Team
- type TeamMember
Constants ¶
const ( ModelOrganization = "organization" ModelMember = "member" ModelInvitation = "invitation" ModelTeam = "team" ModelTeamMember = "teamMember" ModelOrganizationRole = "organizationRole" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AddMemberInput ¶
type AddMemberInput struct {
Database betterauth.DatabaseAdapter
OrganizationID string
UserID string
Roles []string
ActorUserID string
Clock betterauth.Clock
GenerateID func() (string, error)
}
type Config ¶
type Config struct {
CreatorRole string
Roles map[string]Role
Statements map[string][]string
InvitationTTL time.Duration
MaxOrganizationsPerUser int
MaxMembersPerOrganization int
MaxInvitationsPerOrganization int
MaxTeamsPerOrganization int
MaxRolesPerOrganization int
DeliverInvitation InvitationDelivery
Hooks Hooks
Schema betterauth.Schema
}
type FullOrganization ¶
type FullOrganization struct {
Organization
Members []Member `json:"members"`
Teams []Team `json:"teams"`
}
FullOrganization is returned by get-full-organization. User records are intentionally not embedded; applications can join public profile data at their boundary without expanding this plugin's disclosure surface.
type Hooks ¶
type Hooks struct {
BeforeOrganizationCreate func(*betterauth.HookContext, *Organization) error
AfterOrganizationCreate func(*betterauth.HookContext, Organization) error
BeforeMemberCreate func(*betterauth.HookContext, *Member) error
AfterMemberCreate func(*betterauth.HookContext, Member) error
BeforeInvitationCreate func(*betterauth.HookContext, *Invitation) error
AfterInvitationCreate func(*betterauth.HookContext, Invitation) error
BeforeMutation func(*betterauth.HookContext, MutationEvent) error
AfterMutation func(*betterauth.HookContext, MutationEvent) error
}
type Invitation ¶
type Invitation struct {
ID string `json:"id"`
OrganizationID string `json:"organizationId"`
Email string `json:"email"`
Role string `json:"role"`
TeamID string `json:"teamId,omitempty"`
Status string `json:"status"`
InviterID string `json:"inviterId"`
ExpiresAt time.Time `json:"expiresAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type InvitationDelivery ¶
type InvitationDelivery func( *betterauth.HookContext, Invitation, Organization, betterauth.User, ) error
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager exposes the plugin descriptor and trusted server-only operations.
func NewManager ¶
func (*Manager) AddMember ¶
AddMember creates a membership from trusted server code. It is deliberately not exposed over HTTP. The caller is responsible for its own authorization.
func (*Manager) Plugin ¶
func (manager *Manager) Plugin() betterauth.Plugin
type MutationEvent ¶
type MutationEvent struct {
Action string `json:"action"`
OrganizationID string `json:"organizationId,omitempty"`
SubjectID string `json:"subjectId,omitempty"`
Data map[string]any `json:"data,omitempty"`
}
MutationEvent is passed to the generic organization lifecycle hooks. Data is a detached copy and must not be used as an authorization signal.
type Organization ¶
type OrganizationRole ¶
type Permission ¶
type Role ¶
type Role struct {
Permission Permission
}