Architecture: How should user identity flow from AI Panel to Vitto chat ba...

Documentation for Sessions

🏗️ Architecture: How should user identity flow from AI Panel to Vitto chat ba...

Date: 2026-02-11
Time: 22:23:17 UTC
Session: gspace1-106.9
Agent: backend
Confidence: 90%
Status: ✅ Documented


📋 Decision Context

Question:

How should user identity flow from AI Panel to Vitto chat backend?

Task: Fix AI Panel identity for Vitto personalization


🎯 Decision Made

Chosen:

Read from TenantContext first, fallback to auth_backup localStorage — pass through to /ai-api/chat

Options Considered:

  1. Import AuthService directly in AI Panel
  2. Read from TenantContext + auth_backup localStorage fallback
  3. Only pass userId and let backend do all profile lookups

💭 Reasoning

The AI Panel (vitto-hub) is designed to work in multiple contexts: Chrome extension, embedded iframe, direct access. AuthService may not be available in all. TenantContext is the established contract between host (ExtensionPanel) and panel. Added userName/userEmail to TenantContext interface so extension hosts can pass it. For direct access (localhost), reading auth_backup from localStorage is the same proven pattern used by admin-role.guard.ts. This two-source approach (TenantContext → localStorage fallback) ensures identity flows regardless of hosting context. The backend then does authoritative profile lookup from MongoDB by userId.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation