Improve demo tennat and user get
This commit is contained in:
@@ -212,17 +212,18 @@ async def create_demo_session(
|
||||
# Add error handling for the task to prevent silent failures
|
||||
task.add_done_callback(lambda t: _handle_task_result(t, session.session_id))
|
||||
|
||||
# Get complete demo account data from config (includes user, tenant, subscription info)
|
||||
subscription_tier = demo_config.get("subscription_tier", "professional")
|
||||
user_data = demo_config.get("user", {})
|
||||
tenant_data = demo_config.get("tenant", {})
|
||||
|
||||
# Generate session token with subscription data
|
||||
# Map demo_account_type to subscription tier
|
||||
subscription_tier = "enterprise" if session.demo_account_type == "enterprise" else "professional"
|
||||
|
||||
session_token = jwt.encode(
|
||||
{
|
||||
"session_id": session.session_id,
|
||||
"virtual_tenant_id": str(session.virtual_tenant_id),
|
||||
"demo_account_type": request.demo_account_type,
|
||||
"exp": session.expires_at.timestamp(),
|
||||
# NEW: Subscription context (same structure as user JWT)
|
||||
"tenant_id": str(session.virtual_tenant_id),
|
||||
"subscription": {
|
||||
"tier": subscription_tier,
|
||||
@@ -235,14 +236,7 @@ async def create_demo_session(
|
||||
algorithm=settings.JWT_ALGORITHM
|
||||
)
|
||||
|
||||
# Map demo_account_type to subscription tier
|
||||
subscription_tier = "enterprise" if session.demo_account_type == "enterprise" else "professional"
|
||||
tenant_name = (
|
||||
"Panadería Artesana España - Central"
|
||||
if session.demo_account_type == "enterprise"
|
||||
else "Panadería Artesana Madrid - Demo"
|
||||
)
|
||||
|
||||
# Build complete response like a real login would return
|
||||
return {
|
||||
"session_id": session.session_id,
|
||||
"virtual_tenant_id": str(session.virtual_tenant_id),
|
||||
@@ -254,7 +248,29 @@ async def create_demo_session(
|
||||
"session_token": session_token,
|
||||
"subscription_tier": subscription_tier,
|
||||
"is_enterprise": session.demo_account_type == "enterprise",
|
||||
"tenant_name": tenant_name
|
||||
# Complete user data (like a real login response)
|
||||
"user": {
|
||||
"id": user_data.get("id"),
|
||||
"email": user_data.get("email"),
|
||||
"full_name": user_data.get("full_name"),
|
||||
"role": user_data.get("role", "owner"),
|
||||
"is_active": user_data.get("is_active", True),
|
||||
"is_verified": user_data.get("is_verified", True),
|
||||
"tenant_id": str(session.virtual_tenant_id),
|
||||
"created_at": session.created_at.isoformat()
|
||||
},
|
||||
# Complete tenant data
|
||||
"tenant": {
|
||||
"id": str(session.virtual_tenant_id),
|
||||
"name": demo_config.get("name"),
|
||||
"subdomain": demo_config.get("subdomain"),
|
||||
"subscription_tier": subscription_tier,
|
||||
"tenant_type": demo_config.get("tenant_type", "standalone"),
|
||||
"business_type": tenant_data.get("business_type"),
|
||||
"business_model": tenant_data.get("business_model"),
|
||||
"description": tenant_data.get("description"),
|
||||
"is_active": True
|
||||
}
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user