Skip to content

Commit cf01c18

Browse files
Yang YiHeleonai-agent
authored andcommitted
fix(auth): derive entity_id from user_id instead of reading from Supabase JWT
Supabase JWTs don't carry custom claims. entity_id for human users is always {user_id}-1 by convention, so derive it rather than expecting it in the token payload.
1 parent b2c9781 commit cf01c18

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎backend/web/core/dependencies.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ async def get_current_user_id(request: Request) -> str:
6161

6262

6363
async def get_current_entity_id(request: Request) -> str:
64-
"""Extract entity_id from JWT. Used for chat/social scoping (Entity = Thread's identity)."""
65-
payload = _extract_jwt_payload(request)
66-
entity_id = payload.get("entity_id")
67-
if not entity_id:
68-
raise HTTPException(401, "Token missing entity_id — please re-login")
69-
return entity_id
64+
"""Derive entity_id for the authenticated human user.
65+
66+
Supabase JWTs do not carry custom claims, so entity_id is derived
67+
from user_id using the stable convention: human entity = f"{user_id}-1".
68+
"""
69+
user_id = await get_current_user_id(request)
70+
if _DEV_SKIP_AUTH:
71+
return _DEV_PAYLOAD.get("entity_id", user_id)
72+
return f"{user_id}-1"
7073

7174

7275
async def verify_thread_owner(

0 commit comments

Comments
 (0)