diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx
index a25738c..c3918fb 100644
--- a/frontend/src/app/layout.tsx
+++ b/frontend/src/app/layout.tsx
@@ -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 && }
+
{config.showAuthStatus && }
{children}
{config.showNav && }
diff --git a/frontend/src/components/SessionChecker.tsx b/frontend/src/components/SessionChecker.tsx
index f51f250..f08a077 100644
--- a/frontend/src/components/SessionChecker.tsx
+++ b/frontend/src/components/SessionChecker.tsx
@@ -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 (
-
- Session available!
-
- );
- }
+ getSessions();
+ }, [auth, path]);
return <> >;
}