We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
A comprehensive team management system that adds multi-tenancy support to your Phoenix application. Automatically creates personal teams for users and provides full team collaboration features including invitations, role-based permissions, and team switching functionality.
Key Benefits
Implementation Details
The feature extends your existing User schema with team relationships and adds a scoping system for multi-tenant data access:
# Adds to User schema
field :current_team_id, :binary_id
has_one :personal_team, MyApp.Teams.Team, foreign_key: :created_by_user_id
has_many :memberships, MyApp.Teams.Membership
has_many :teams, through: [:memberships, :team]
Includes five new schemas: Team
, Membership
, Member
, Invitation
, and extends your user authentication pipeline with team scoping. The Scope
struct tracks both current user and active team context throughout the application.
Usage Example
# Get user with team context
user = Users.get_user!(id) |> Users.with_memberships()
# Switch teams
Users.switch_team(user, team_id)
# Create team with automatic membership
Teams.create_team_with_membership(attrs, user)
# Invite team members
Teams.create_invitation(team, %{email: "user@example.com", role: "member"})
Configuration
Run the installer and update your router to include team management routes. The feature automatically modifies your authentication pipeline to load team context and provides LiveView components for team switching in your layout. Database migrations handle the new team-related tables with proper foreign key constraints.