Skip to content

feat: Phase 1 — Database, Auth, Companies, Agents#2

Merged
pysnooLab merged 27 commits intomainfrom
feat/phase1-db-auth-admin
Apr 7, 2026
Merged

feat: Phase 1 — Database, Auth, Companies, Agents#2
pysnooLab merged 27 commits intomainfrom
feat/phase1-db-auth-admin

Conversation

@pysnooLab
Copy link
Copy Markdown
Collaborator

Summary

Phase 1 implementation (Tasks 1-10 of 15):

Database (Supabase)

  • Complete schema: 4 enums, 8 tables, indexes
  • RLS policies for admin/agent/customer_manager scoping
  • Signup trigger: first user becomes admin, subsequent users need invite token
  • Generated TypeScript types from schema

Authentication

  • AuthProvider context (user, profile, session)
  • Login page (email/password)
  • Signup page (open first admin + invite token flow)
  • ProtectedRoute + RoleGuard for route protection
  • Role-based sidebar navigation

Companies (admin only)

  • List, create, edit, delete
  • Company detail page
  • Invite Customer Manager dialog (generates token link + copy button)

Agents (admin only)

  • Agent list with assigned company badges
  • Invite Agent dialog (email + optional company multi-select)
  • Assign/remove companies dialog

Remaining (Tasks 11-15, next PR)

  • Customers CRUD (customer manager)
  • Tickets list, detail, messages, create
  • Dashboard with stats

Test plan

  • npm run build succeeds
  • npm test — unit tests pass
  • npx supabase start && npx supabase db reset — migrations apply cleanly
  • First signup creates admin account
  • Admin can create companies
  • Admin can invite customer manager (generates link)
  • Admin can invite agent and assign companies
  • Signup with invite token works
  • Role-based navigation shows correct items per role

🤖 Generated with Claude Code

pysnooLab and others added 27 commits April 7, 2026 12:11
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d data

Fix critical security vulnerabilities (RLS role escalation, invite token
exposure, server-side token verification), improve error handling across
all mutation calls, fix type safety issues, eliminate N+1 query in
useAgents, standardize zod imports, and add comprehensive seed data for
local development.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…DE.md

Codify lessons learned from Phase 1 PR review into project guidelines
to prevent recurring issues: RLS policy security rules, error handling
patterns, consistent zod imports, and query optimization rules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add atomic RPC functions (update_agent_companies, create_invite) replacing
  non-atomic client-side delete-then-insert patterns
- Move invite token generation server-side (gen_random_bytes)
- Add WITH CHECK to ticket update policies preventing cross-company moves
- Add email_logs table and types (was missing from schema)
- Remove single-admin unique index, use advisory lock instead
- Fix non-null assertions in useProfile/useCompany with explicit guards
- Fix uncaught promises: SignupForm validateToken, clipboard handlers
- Fix signOut error handling in AppLayout (visible error, no console.error)
- Add query error rendering in CompanyDetail
- Use validate_invite RPC in SignupForm (replaces dropped USING(true) policy)
- Sync CLAUDE.md data model with actual table names
- Add 29 unit tests: useAuth, AuthProvider, ProtectedRoute, RoleGuard,
  useAgentCompanies, useCreateInvite, useCompanies
- Add e2e tests: auth flows, navigation, form validation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add testing patterns: .test.tsx for JSX, supabase mocking, test-utils
- Add RLS rules: server-side tokens, SECURITY DEFINER RPCs, advisory locks
- Add error handling: clipboard catch, null guards in queryFn, no console.error
- Fix stale references to user_roles → profiles in Supabase Guidelines
- Update memory files with architecture patterns and review learnings

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Suppress react-refresh/only-export-components for shadcn ui files and AuthProvider hook co-export
- Replace useEffect setState with onOpenChange callback in AssignCompaniesDialog
- Guard duplicate validation in SignupForm with useRef
- Fix constant binary expression in utils test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Runs lint, typecheck+build, and unit tests in parallel on every PR
targeting main and on pushes to main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add migration 00006: DEFAULT for p_company_ids so PostgREST can
  resolve the function when the parameter is omitted
- Omit p_company_ids from RPC call when companyIds is empty
- Add unit test for empty companyIds case
- Add E2E Tests job to CI workflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move auth.users inserts to migration 00007 (which can drop/recreate
  the trigger since postgres owns handle_new_user)
- Seed.sql now only handles public schema tables
- Profiles are inserted by seed.sql with correct roles

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
pgcrypto lives in the extensions schema on Supabase, but create_invite()
had search_path = public. Add extensions to the search_path so
gen_random_bytes() resolves correctly.

Also fix 4 failing e2e tests (CardTitle renders a div, not a heading)
and add invite-agent e2e tests covering the full invite flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use 4 workers instead of 1 in CI, and serve the production build via
`vite preview` instead of the dev server for faster test execution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Without Supabase running, all e2e tests timeout waiting for UI elements
that never render. Uses supabase/setup-cli with minimal services to keep
startup fast.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pysnooLab pysnooLab merged commit ccda78f into main Apr 7, 2026
4 checks passed
@pysnooLab pysnooLab deleted the feat/phase1-db-auth-admin branch April 7, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant