auto connects user to session if available #26
@@ -23,26 +23,22 @@ const pageConfig: Record<
|
||||
string,
|
||||
{
|
||||
showAuthStatus: boolean;
|
||||
showSessionChecker: boolean;
|
||||
showNav: boolean;
|
||||
showQuota: boolean;
|
||||
}
|
||||
> = {
|
||||
"/nominations": {
|
||||
showAuthStatus: true,
|
||||
showSessionChecker: false,
|
||||
showQuota: true,
|
||||
showNav: navToggle,
|
||||
},
|
||||
"/mobile-voting": {
|
||||
showAuthStatus: false,
|
||||
showSessionChecker: false,
|
||||
showQuota: false,
|
||||
showNav: false,
|
||||
},
|
||||
"/lobby": {
|
||||
showAuthStatus: true,
|
||||
showSessionChecker: false,
|
||||
showQuota: true,
|
||||
showNav: navToggle,
|
||||
},
|
||||
@@ -60,7 +56,7 @@ function LayoutContent({ children }: { children: React.ReactNode }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{config.showSessionChecker && <SessionChecker />}
|
||||
<SessionChecker />
|
||||
{config.showAuthStatus && <AuthStatus />}
|
||||
{children}
|
||||
{config.showNav && <NavigationBar />}
|
||||
|
||||
@@ -11,44 +11,28 @@ import getSessionId from "muzak/data/session";
|
||||
export default function SessionChecker() {
|
||||
const auth = useAuth();
|
||||
const router = useRouter();
|
||||
const path = usePathname();
|
||||
|
||||
const [isSession, setIsSession] = useState(false);
|
||||
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) {
|
||||
const user = getUser();
|
||||
setSessionId(sessions[0].session_id);
|
||||
if (sessions[0].host !== user?.profile?.email) {
|
||||
if (path !== "/mobile-voting") {
|
||||
router.push("/mobile-voting");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
//getSessionId();
|
||||
console.log("hheufheufh");
|
||||
}, [auth]);
|
||||
|
||||
if (sessionId) {
|
||||
return (
|
||||
<Link
|
||||
href={link}
|
||||
className="bold text-l absolute top-2 left-2 rounded-[50%] bg-red-500 p-3 font-bold text-white"
|
||||
>
|
||||
Session available!
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
getSessions();
|
||||
}, [auth, path]);
|
||||
return <> </>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user