New token arch

This commit is contained in:
Urtzi Alfaro
2026-01-10 21:45:37 +01:00
parent cc53037552
commit bf1db7cb9e
26 changed files with 1751 additions and 107 deletions

View File

@@ -212,13 +212,24 @@ 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))
# Generate session token
# 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()
"exp": session.expires_at.timestamp(),
# NEW: Subscription context (same structure as user JWT)
"tenant_id": str(session.virtual_tenant_id),
"subscription": {
"tier": subscription_tier,
"status": "active",
"valid_until": session.expires_at.isoformat()
},
"is_demo": True
},
settings.JWT_SECRET_KEY,
algorithm=settings.JWT_ALGORITHM