organization

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package organization provides Better Auth-shaped multi-tenant organization management and authorization.

Index

Constants

View Source
const (
	ModelOrganization     = "organization"
	ModelMember           = "member"
	ModelInvitation       = "invitation"
	ModelTeam             = "team"
	ModelTeamMember       = "teamMember"
	ModelOrganizationRole = "organizationRole"
)

Variables

This section is empty.

Functions

func New

func New(config Config) (betterauth.Plugin, error)

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 Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager exposes the plugin descriptor and trusted server-only operations.

func NewManager

func NewManager(config Config) (*Manager, error)

func (*Manager) AddMember

func (manager *Manager) AddMember(
	ctx context.Context,
	input AddMemberInput,
) (Member, error)

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 Member

type Member struct {
	ID             string    `json:"id"`
	OrganizationID string    `json:"organizationId"`
	UserID         string    `json:"userId"`
	Role           string    `json:"role"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

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 Organization struct {
	ID        string         `json:"id"`
	Name      string         `json:"name"`
	Slug      string         `json:"slug"`
	Metadata  map[string]any `json:"metadata,omitempty"`
	CreatedAt time.Time      `json:"createdAt"`
	UpdatedAt time.Time      `json:"updatedAt"`
}

type OrganizationRole

type OrganizationRole struct {
	ID             string     `json:"id"`
	OrganizationID string     `json:"organizationId"`
	Role           string     `json:"role"`
	Permission     Permission `json:"permission"`
	CreatedAt      time.Time  `json:"createdAt"`
	UpdatedAt      time.Time  `json:"updatedAt"`
}

type Permission

type Permission map[string][]string

type Role

type Role struct {
	Permission Permission
}

type Team

type Team struct {
	ID             string    `json:"id"`
	OrganizationID string    `json:"organizationId"`
	Name           string    `json:"name"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

type TeamMember

type TeamMember struct {
	ID        string    `json:"id"`
	TeamID    string    `json:"teamId"`
	UserID    string    `json:"userId"`
	CreatedAt time.Time `json:"createdAt"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL