Skip to content

Commit 5ca6c49

Browse files
feat: refactor room joining logic and implement InRoomWrapper for user authentication
1 parent 30c7d12 commit 5ca6c49

File tree

5 files changed

+305
-169
lines changed

5 files changed

+305
-169
lines changed

backend/src/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ io.on("connection", (socket) => {
2626
console.log(`🟢 User connected: ${socket.id}`);
2727

2828
// ---------------- Join Room ----------------
29-
socket.on("join-room", async (roomId: string, userName: string) => {
30-
try {
31-
socket.join(roomId);
32-
console.log(`👥 ${userName} joined room ${roomId}`);
29+
socket.on("join-room", async ({ roomId, userName }: { roomId: string; userName: string }) => {
30+
try {
31+
socket.join(roomId);
32+
console.log(`👥 ${userName} joined room ${roomId}`);
3333

3434
// Notify others
3535
io.to(roomId).emit("user-joined", { userName, roomId });

frontend/src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import InRoom from "./pages/InRoom.js";
1515
import CreateRoomLobby from "./pages/CreateRoomLobby.js";
1616
import CreateRoom from "./pages/CreateRoom.js";
1717
import ActiveSessions from "./pages/ActiveSessions.js";
18+
import InRoomWrapper from "./pages/InRoomWrapper.js";
1819
const queryClient = new QueryClient();
1920

2021
const App = () => (
@@ -32,7 +33,7 @@ const App = () => (
3233
<Route path="/oauth-success" element={<OAuthSuccess />} />
3334
<Route path="/create-room" element={<CreateRoom />} /> {/* ✅ */}
3435
<Route path="/join-room" element={<JoinRoom />} /> {/* ✅ */}
35-
<Route path="/room/:roomName" element={<InRoom />} />
36+
<Route path="/room/:roomName" element={<InRoomWrapper />} />
3637
<Route path="/lobby/:roomId" element={<CreateRoomLobby />} />
3738
<Route path="/sessions" element={<ActiveSessions />} />
3839
</Routes>

frontend/src/pages/CreateRoomLobby.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function CreateRoomLobby() {
2929
}
3030
};
3131
fetchRoom();
32-
}, [roomId]);
32+
}, [roomId,roomName]);
3333

3434
// Copy join link to clipboard
3535
const handleCopyLink = () => {
@@ -73,7 +73,7 @@ export default function CreateRoomLobby() {
7373
</p>
7474

7575
<Button
76-
onClick={() => navigate(`/room/${roomId}`)}
76+
onClick={() => navigate(`/room/${roomName}`)}
7777
className="mt-6 w-full bg-green-600 hover:bg-green-700 text-white font-medium py-3 rounded-lg shadow-md"
7878
>
7979
Go to Room

0 commit comments

Comments
 (0)