Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6527,13 +6527,22 @@ async def on_fetch(self, request):
user_param = (qs.get("user_id") or [None])[0]
display_param = (qs.get("display_name") or [None])[0]

allow_anon_raw = getattr(self.env, "ALLOW_ANON_PRESENCE", "true")
allow_anon = str(allow_anon_raw).strip().lower() in ("true", "1", "yes")

authenticated_user = verify_token(token_param or "", self.env.JWT_SECRET) if token_param else None
can_interact = authenticated_user is not None

if authenticated_user:
user_id = str(authenticated_user.get("id", ""))
display_name = str(authenticated_user.get("username") or user_id)
can_interact = True
else:
if not allow_anon:
return Response(
json.dumps({"error": "Authentication required"}),
status=401,
headers={"Content-Type": "application/json"},
)
if token_param or not user_param:
return Response(
json.dumps({"error": "Authentication required"}),
Expand All @@ -6542,6 +6551,7 @@ async def on_fetch(self, request):
)
user_id = str(user_param)
display_name = str(display_param or user_id)
can_interact = True

user_id = user_id[:64]
display_name = display_name[:64]
Expand Down