diff --git a/packages/nextjs/app/polls/[id]/page.tsx b/packages/nextjs/app/polls/[id]/page.tsx index 974cf34..c527a6d 100644 --- a/packages/nextjs/app/polls/[id]/page.tsx +++ b/packages/nextjs/app/polls/[id]/page.tsx @@ -2,9 +2,11 @@ import { useParams } from "next/navigation"; import PollDetail from "~~/components/PollDetail"; +import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; export default function PollDetailPage() { const { id } = useParams<{ id: string }>(); + useAuthUserOnly({}); return ; } diff --git a/packages/nextjs/app/polls/page.tsx b/packages/nextjs/app/polls/page.tsx index a13fd97..3347319 100644 --- a/packages/nextjs/app/polls/page.tsx +++ b/packages/nextjs/app/polls/page.tsx @@ -4,6 +4,7 @@ import { useState } from "react"; import { useRouter } from "next/navigation"; import Paginator from "~~/components/Paginator"; import HoverBorderCard from "~~/components/card/HoverBorderCard"; +import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; import { useFetchPolls } from "~~/hooks/useFetchPolls"; import { useTotalPages } from "~~/hooks/useTotalPages"; @@ -12,6 +13,7 @@ export default function Polls() { const [limit] = useState(10); const { totalPolls, polls } = useFetchPolls(currentPage, limit); const totalPages = useTotalPages(totalPolls, limit); + useAuthUserOnly({}); console.log(polls); diff --git a/packages/nextjs/components/PollDetail.tsx b/packages/nextjs/components/PollDetail.tsx index af81a18..f61ac1d 100644 --- a/packages/nextjs/components/PollDetail.tsx +++ b/packages/nextjs/components/PollDetail.tsx @@ -7,7 +7,6 @@ import { useContractRead, useContractWrite } from "wagmi"; import PollAbi from "~~/abi/Poll"; import VoteCard from "~~/components/card/VoteCard"; import { useAuthContext } from "~~/contexts/AuthContext"; -import { useAuthUserOnly } from "~~/hooks/useAuthUserOnly"; import { useFetchPoll } from "~~/hooks/useFetchPoll"; import { getPollStatus } from "~~/hooks/useFetchPolls"; import { PollStatus, PollType } from "~~/types/poll"; @@ -18,8 +17,6 @@ export default function PollDetail({ id }: { id: bigint }) { const { data: poll, error, isLoading } = useFetchPoll(id); const [pollType, setPollType] = useState(PollType.NOT_SELECTED); - useAuthUserOnly({}); - const { keypair, stateIndex } = useAuthContext(); const [votes, setVotes] = useState<{ index: number; votes: number }[]>([]); diff --git a/packages/nextjs/contexts/AuthContext.tsx b/packages/nextjs/contexts/AuthContext.tsx index 5fdd785..4228061 100644 --- a/packages/nextjs/contexts/AuthContext.tsx +++ b/packages/nextjs/contexts/AuthContext.tsx @@ -76,8 +76,12 @@ export default function AuthContextProvider({ children }: { children: React.Reac return; } - const lastSignUpEvent = SignUpEvents[SignUpEvents.length - 1]; - setStateIndex(lastSignUpEvent.args._stateIndex || null); + const event = SignUpEvents.filter( + log => + log.args._userPubKeyX?.toString() === keypair.pubKey.asContractParam().x && + log.args._userPubKeyY?.toString() === keypair.pubKey.asContractParam().y, + )[0]; + setStateIndex(event?.args?._stateIndex || null); }, [keypair, SignUpEvents]); useScaffoldEventSubscriber({