From ef211523274875a458c5addf4145e0b68093fb26 Mon Sep 17 00:00:00 2001 From: Ong Jun Xiong Date: Sat, 11 Nov 2023 18:02:06 +0800 Subject: [PATCH] kick one user out the moment the other user leaves --- frontend/src/pages/room/[id].tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/room/[id].tsx b/frontend/src/pages/room/[id].tsx index 773f4f77..118b480a 100644 --- a/frontend/src/pages/room/[id].tsx +++ b/frontend/src/pages/room/[id].tsx @@ -14,12 +14,13 @@ import { MrMiyagi } from "@uiball/loaders"; import { useMatchmaking } from "@/hooks/useMatchmaking"; import Solution from "@/components/room/solution"; import { AuthContext } from "@/contexts/AuthContext"; +import { toast } from "react-toastify"; export default function Room() { const router = useRouter(); const roomId = router.query.id as string; const { user: currentUser } = useContext(AuthContext); - const userId = (currentUser.uid as string) || "user1"; + const userId = (currentUser?.uid as string) || "user1"; const disableVideo = (router.query.disableVideo as string)?.toLowerCase() === "true"; @@ -59,6 +60,13 @@ export default function Room() { }); } + if (!match) { + // leave room and redirect to interviews page + leaveMatch(); + toast.info("Other user has left"); + router.push("/interviews"); + } + setLoading(false); // eslint-disable-next-line react-hooks/exhaustive-deps }, [match, questionId]);