fix: validate room existence before generating join token (#154) - #172
fix: validate room existence before generating join token (#154)#172Muneerali199 wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThe Join Room Appwrite function now receives database IDs, validates additional Appwrite environment variables, checks room existence before issuing a token, and returns 404 when the room is missing. ChangesJoin Room room validation
Sequence Diagram(s)sequenceDiagram
participant Client
participant JoinRoomFunction
participant AppwriteDatabases
Client->>JoinRoomFunction: request with roomName and uid
JoinRoomFunction->>AppwriteDatabases: listDocuments(name == roomName)
AppwriteDatabases-->>JoinRoomFunction: room documents or empty list
JoinRoomFunction-->>Client: 404 "Room not found" or success token response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@functions/join-room/src/main.js`:
- Line 1: The Join Room function imports Client and Databases from
node-appwrite, but the function package dependencies do not include that module.
Update the Join Room function’s package manifest to add node-appwrite alongside
livekit-server-sdk so the import used in main.js resolves during install and
runtime.
- Around line 34-38: The room lookup in join-room’s main flow is using the
user-entered roomName as the Appwrite document ID, but create-room generates a
different unique ID via ID.unique(). Update the room existence check in
join-room’s getDocument logic to query the Rooms collection by the room name
field instead, or change the client flow to pass the वास्तविक room ID returned
by create-room. Use the existing roomExists check in join-room/src/main.js and
the create-room Appwrite document creation path as the reference points.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d0c321d1-f567-42d3-aa6c-b33d07cd4921
📒 Files selected for processing (2)
appwrite.jsonfunctions/join-room/src/main.js
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@functions/join-room/src/main.js`:
- Around line 34-37: The join-room lookup in main.js uses Query.equal("name",
roomName), but the rooms collection does not currently index name, so the query
cannot run reliably. Update the appwrite.json configuration for the rooms
collection to add an index on the name attribute, and verify the join-room flow
continues to use databases.listDocuments with Query.equal against that indexed
field.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 06b3bb39-ba83-45ce-acba-ea3256ddddf0
📒 Files selected for processing (2)
functions/join-room/package.jsonfunctions/join-room/src/main.js
| const rooms = await databases.listDocuments( | ||
| process.env.MASTER_DATABASE_ID, | ||
| process.env.ROOMS_COLLECTION_ID, | ||
| [Query.equal("name", roomName)] |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect the Appwrite schema/config and the room creation contract for the queried field.
fd '^appwrite\.json$' . --exec sh -c '
echo "### $1"
sed -n "1,260p" "$1"
' sh {}
fd '^appwrite\.js$' functions/create-room --exec sh -c '
echo "### $1"
sed -n "1,220p" "$1"
' sh {}
rg -n -C3 'ROOMS_COLLECTION_ID|Query\.equal|createDocument|listDocuments|\bname\b' \
appwrite.json functions/create-room functions/join-roomRepository: AOSSIE-Org/Resonate-Backend
Length of output: 34202
🏁 Script executed:
#!/bin/bash
sed -n '846,930p' appwrite.jsonRepository: AOSSIE-Org/Resonate-Backend
Length of output: 2865
Add an index for rooms.name
appwrite.json defines rooms.name, but the rooms collection has no indexes. Query.equal("name", roomName) needs an indexed attribute, so joins will fail until name is indexed.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@functions/join-room/src/main.js` around lines 34 - 37, The join-room lookup
in main.js uses Query.equal("name", roomName), but the rooms collection does not
currently index name, so the query cannot run reliably. Update the appwrite.json
configuration for the rooms collection to add an index on the name attribute,
and verify the join-room flow continues to use databases.listDocuments with
Query.equal against that indexed field.
Description
Adds room existence validation in the join-room function before generating LiveKit access tokens. Previously, tokens were issued for any room name without checking if the room actually exists in Appwrite.
Changes
databases.getDocument()before token generation. Returns 404 if room not found.MASTER_DATABASE_IDandROOMS_COLLECTION_IDenv vars for the join-room function.Acceptance criteria
Fixes #154
Summary by CodeRabbit