session link with mobile voting

This commit is contained in:
2025-08-15 18:30:57 +02:00
parent cbc9be1f63
commit a1526ddc67
3 changed files with 121 additions and 21 deletions
+22 -20
View File
@@ -6,6 +6,7 @@ import { useRouter, usePathname } from "next/navigation";
import { api, Session } from "muzak/data/fetcher";
import { getUser } from "muzak/data/fetcher";
import { useSession } from "muzak/contexts/SessionContext";
import getSessionId from "muzak/data/session";
export default function SessionChecker() {
const auth = useAuth();
@@ -15,30 +16,31 @@ export default function SessionChecker() {
const [link, setLink] = useState("/lobby");
const { sessionId, setSessionId } = useSession();
async function getSessions() {
if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
const { data: sessions } = await api?.sessions?.list({});
console.log(sessions);
if (sessions?.length > 0) {
setIsSession(true);
const user = getUser();
setSessionId(sessions[0].session_id);
if (sessions[0].host === user?.profile?.email) {
setLink("/lobby");
} else {
setLink("/session");
}
} else {
setIsSession(false);
}
}
}
// async function getSessions() {
// if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
// const { data: sessions } = await api?.sessions?.list({});
// console.log(sessions);
// if (sessions?.length > 0) {
// setIsSession(true);
// const user = getUser();
// setSessionId(sessions[0].session_id);
// if (sessions[0].host === user?.profile?.email) {
// setLink("/lobby");
// } else {
// setLink("/session");
// }
// } else {
// setIsSession(false);
// }
// }
// }
useEffect(() => {
getSessions();
getSessionId();
console.log("hheufheufh");
}, [auth]);
if (isSession) {
if (sessionId) {
return (
<Link
href={link}