Invite Codes

Invite codes gate access to the org setup wizard. Only users with a valid code can create a new organization.

Schema

ColumnTypeDescription
idUUIDPrimary key
codeTEXTUnique invite code string
max_usesINTMaximum allowed uses (NULL = unlimited)
times_usedINTCurrent usage count
expires_atTIMESTAMPTZOptional expiration
created_atTIMESTAMPTZCreation timestamp

Validation Rules

An invite code is valid when:

  • The code exists in the database
  • times_used < max_uses (or max_uses is NULL)
  • expires_at is NULL or in the future

Usage Flow

  1. User enters code on the setup wizard
  2. Backend validates the code via GetInviteCodeByCode query
  3. If valid, times_used is incremented
  4. A setup JWT is issued containing the invite_code_id
  5. All subsequent wizard steps use this JWT for authentication

Creating Invite Codes

Currently, invite codes are managed directly in the database:

-- Create an invite code with 100 max uses
INSERT INTO invite_codes (code, max_uses)
VALUES ('WELCOME-2024', 100);
 
-- Create an unlimited invite code
INSERT INTO invite_codes (code)
VALUES ('UNLIMITED-DEV');
 
-- Create a code that expires
INSERT INTO invite_codes (code, max_uses, expires_at)
VALUES ('PROMO-Q1', 50, '2025-03-31T23:59:59Z');

Development

For local development, seed a test invite code:

INSERT INTO invite_codes (code, max_uses) VALUES ('DEV-INVITE-001', 100);