Skip to content

Commit

Permalink
kick one user out the moment the other user leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
ong6 committed Nov 11, 2023
1 parent 92045b3 commit ef21152
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion frontend/src/pages/room/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit ef21152

Please sign in to comment.