Add improvements
This commit is contained in:
@@ -367,26 +367,47 @@ async def get_profile(
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""Get user profile - works for JWT auth AND demo sessions"""
|
||||
logger.info(f"📋 Profile request received",
|
||||
user_id=current_user.get("user_id"),
|
||||
is_demo=current_user.get("is_demo", False),
|
||||
demo_session_id=current_user.get("demo_session_id", ""),
|
||||
email=current_user.get("email", ""),
|
||||
path="/api/v1/auth/me")
|
||||
try:
|
||||
user_id = current_user.get("user_id")
|
||||
|
||||
if not user_id:
|
||||
logger.error(f"❌ No user_id in current_user context for profile request",
|
||||
current_user=current_user)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid user context"
|
||||
)
|
||||
|
||||
logger.info(f"🔎 Fetching user profile for user_id: {user_id}",
|
||||
is_demo=current_user.get("is_demo", False),
|
||||
demo_session_id=current_user.get("demo_session_id", ""))
|
||||
|
||||
# Fetch user from database
|
||||
from app.repositories import UserRepository
|
||||
user_repo = UserRepository(User, db)
|
||||
user = await user_repo.get_by_id(user_id)
|
||||
|
||||
if not user:
|
||||
logger.error(f"🚨 User not found in database",
|
||||
user_id=user_id,
|
||||
is_demo=current_user.get("is_demo", False))
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="User profile not found"
|
||||
)
|
||||
|
||||
logger.info(f"🎉 User profile found",
|
||||
user_id=user.id,
|
||||
email=user.email,
|
||||
full_name=user.full_name,
|
||||
is_active=user.is_active)
|
||||
|
||||
return UserResponse(
|
||||
id=str(user.id),
|
||||
email=user.email,
|
||||
|
||||
@@ -30,14 +30,6 @@ router = APIRouter(prefix="/internal/demo", tags=["internal"])
|
||||
DEMO_TENANT_PROFESSIONAL = "a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6"
|
||||
|
||||
|
||||
def verify_internal_api_key(x_internal_api_key: Optional[str] = Header(None)):
|
||||
"""Verify internal API key for service-to-service communication"""
|
||||
if x_internal_api_key != settings.INTERNAL_API_KEY:
|
||||
logger.warning("Unauthorized internal API access attempted")
|
||||
raise HTTPException(status_code=403, detail="Invalid internal API key")
|
||||
return True
|
||||
|
||||
|
||||
@router.post("/clone")
|
||||
async def clone_demo_data(
|
||||
base_tenant_id: str,
|
||||
@@ -45,8 +37,7 @@ async def clone_demo_data(
|
||||
demo_account_type: str,
|
||||
session_id: Optional[str] = None,
|
||||
session_created_at: Optional[str] = None,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
_: bool = Depends(verify_internal_api_key)
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Clone auth service data for a virtual demo tenant
|
||||
@@ -226,7 +217,7 @@ async def clone_demo_data(
|
||||
|
||||
|
||||
@router.get("/clone/health")
|
||||
async def clone_health_check(_: bool = Depends(verify_internal_api_key)):
|
||||
async def clone_health_check():
|
||||
"""
|
||||
Health check for internal cloning endpoint
|
||||
Used by orchestrator to verify service availability
|
||||
|
||||
Reference in New Issue
Block a user