SuperAPI AI Directory

bootstrap-user-management

Coding & development

View repository

Updated 10-15 19:52

About this skill

Bootstrap User Management

Add account member management to a Phoenix 1.8 app that already has multi-tenant accounts set up via /bootstrap-accounts. Provides a LiveView for listing members, inviting users by email, role assignment, and member removal with safety guards.

Prerequisites

Verify before starting:

  1. /bootstrap-accounts has been run (accounts table, account_users table, Account schema, AccountUser schema, Accounts context, AccountContext module, LoadAccount plug, account-scoped router all exist)
  2. phx.gen.auth completed (User schema, UserAuth module exist)
  3. DaisyUI installed

App Name Detection

Detect the app module name from mix.exs (e.g., MyApp) and the OTP app name (e.g., my_app). Replace all occurrences of MyApp/my_app/MyAppWeb/my_app_web in reference templates with the actual names.

Implementation Order

Execute in this exact order. Read the referenced file for each step's code templates.

Phase 1: Context Functions

Read references/context.md

  1. Add member management functions to the Accounts context: list_account_members/1, get_account_member/2, invite_user_to_account/3, delete_account_member/1, count_account_owners/1, authorize_role_assignment/2, parse_member_role/1

Phase 2: Display Helpers

Read references/helpers.md

  1. Create MemberDisplayHelpers module for shared role and date formatting

Phase 3: LiveView & Form Component

Read references/liveview.md

  1. Create AccountUsersLive LiveView with table display and delete action
  2. Create AccountUserFormComponent for the invite modal

Phase 4: Routes

Read references/routes.md

  1. Add routes for the user management pages inside the existing account-scoped live_session
  2. Add email notification function for invited users

Phase 5: Verify

  1. Run mix compile --warnings-as-errors and fix any issues
  2. Verify the routes exist: mix phx.routes | grep users

Key Patterns

Role hierarchy:

  • :owner — full access, can assign any role including owner
  • :admin — can invite/remove users, cannot assign owner role
  • :member — basic access, no management permissions

Safety guards:

  • Cannot remove yourself
  • Cannot remove the last owner
  • Only admins/owners see the Add User button and Remove links
  • Only owners can assign the owner role
  • Duplicate member detection with friendly error message

LiveView assigns in mount:

  • :active_nav — set to :account_users
  • :current_account_user — the current user's membership in this account
  • :breadcrumbs — navigation breadcrumbs
  • :page_title — browser tab title