# Task Log: WebUI Single-Tenant/Multi-Tenant Mode Support **Date**: 2025-01-06 09:30 **Mode**: Beastmode ## Summary Implemented single-tenant and multi-tenant mode support for the LightRAG WebUI to ensure it works correctly in both configurations. ## Actions Performed 1. **Added `LIGHTRAG_MULTI_TENANT` env var** to `lightrag/api/lightrag_server.py` to control multi-tenant mode 2. **Updated `/auth-status` and `/health` endpoints** to include `multi_tenant_enabled` flag 3. **Updated `LoginPage.tsx`** to auto-redirect in single-tenant mode (bypass tenant selection) 4. **Updated `App.tsx`** to set default tenant AND KB in single-tenant mode 5. **Updated `TenantSelector.tsx`** to skip API calls when `multiTenantEnabled=false` 6. **Updated `SiteHeader.tsx`** to conditionally hide tenant selector in single-tenant mode 7. **Updated `useTenantInitialization.ts`** hook to skip tenant API calls in single-tenant mode 8. **Updated `AuthStore`** in `stores/state.ts` with `multiTenantEnabled` state and `setMultiTenantEnabled` action 9. **Updated `lightrag.ts`** API types to include `multi_tenant_enabled` in `AuthStatusResponse` 10. **Rebuilt WebUI** multiple times during development ## Key Decisions 1. **Default mode is single-tenant** (`LIGHTRAG_MULTI_TENANT=false`) for backward compatibility 2. **Default tenant/KB IDs are "default"** to match API expectations 3. **Auto-set both tenant AND KB** in single-tenant mode to avoid "KB context required" errors 4. **Multi-tenant mode requires separate tenant API routes** to be configured (not fully implemented in current codebase) ## Test Results ### Single-Tenant Mode (Default) - ✅ WebUI loads without errors - ✅ Auto-login with free login mode - ✅ Documents tab works (shows empty state) - ✅ Knowledge Graph tab works (shows empty graph) - ✅ Retrieval tab works with query parameters - ✅ API tab loads Swagger UI (404 for docs endpoints expected) - ✅ No tenant selection UI shown - ✅ No 404 errors for tenant/KB API calls ### Multi-Tenant Mode - ⚠️ Requires tenant API routes to be configured - ⚠️ Shows 404 errors for `/api/v1/tenants` endpoint - ℹ️ Needs TenantService and tenant routes to be included in API server ## Files Modified - `lightrag/api/lightrag_server.py` - `lightrag_webui/src/App.tsx` - `lightrag_webui/src/features/LoginPage.tsx` - `lightrag_webui/src/features/SiteHeader.tsx` - `lightrag_webui/src/components/TenantSelector.tsx` - `lightrag_webui/src/hooks/useTenantInitialization.ts` - `lightrag_webui/src/stores/state.ts` - `lightrag_webui/src/api/lightrag.ts` ## Next Steps 1. To enable full multi-tenant support: - Include tenant routes in API server when `LIGHTRAG_MULTI_TENANT=true` - Set up tenant/KB tables in PostgreSQL - Create default tenant and KB during initialization - Test tenant CRUD operations 2. Consider adding: - Tenant creation UI in WebUI - KB creation UI in WebUI - Tenant switching without page reload ## Lessons Learned 1. The env var name is `LIGHTRAG_MULTI_TENANT`, not `ENABLE_MULTI_TENANT` or `ENABLE_MULTI_TENANTS` 2. Both tenant AND KB context must be set for document/graph API calls to work 3. The WebUI uses localStorage to persist tenant/KB selection - must clear for fresh testing 4. React strict mode causes double initialization - need refs to prevent duplicate API calls