diff --git a/src/@components/MainPage/hooks/useBallotLists.ts b/src/@components/MainPage/hooks/useBallotLists.ts index 222b85b7..d498b9bd 100644 --- a/src/@components/MainPage/hooks/useBallotLists.ts +++ b/src/@components/MainPage/hooks/useBallotLists.ts @@ -7,7 +7,11 @@ import { PiickleSWRResponse } from "../../../types/remote/swr"; export function useBallotLists(shoudOnSuspense = false) { const swrSetting = shoudOnSuspense ? { suspense: true } : { suspense: false }; - const { data } = useSWR>(`${PATH.BALLOTS}`, realReq.GET_SWR, swrSetting); + const { data } = useSWR>( + `${PATH.BALLOTS}`, + (url) => realReq.GET_SWR(url, { withCredentials: true }), + swrSetting, + ); return { ballotLists: data?.data, diff --git a/src/@components/VotePage/VoteContent/BeforeVoteList/index.tsx b/src/@components/VotePage/VoteContent/BeforeVoteList/index.tsx index 82531ff6..bf2bdad3 100644 --- a/src/@components/VotePage/VoteContent/BeforeVoteList/index.tsx +++ b/src/@components/VotePage/VoteContent/BeforeVoteList/index.tsx @@ -2,11 +2,8 @@ import { useState } from "react"; import { IcCheckWithNoBg } from "../../../../asset/icon"; import { voteApi } from "../../../../core/api/vote"; -import useAuth from "../../../../core/hooks/useAuth"; import { BallotTopicData } from "../../../../types/ballots"; import { GTM_CLASS_NAME } from "../../../../util/const/gtm"; -import useModal from "../../../@common/hooks/useModal"; -import LoginModal from "../../../@common/LoginModal"; import St from "./style"; interface BeforeVoteListProps { @@ -15,11 +12,8 @@ interface BeforeVoteListProps { } export default function BeforeVoteList(props: BeforeVoteListProps) { - const { isLogin } = useAuth(); const { ballotTopic, mutateBallotState } = props; - const { isModalOpen: isLoginModalOpen, toggleModal: toggleLoginModal } = useModal(); - const [currentIdx, setCurrentIdx] = useState(""); const handleClickItem = (key: string) => { @@ -29,20 +23,10 @@ export default function BeforeVoteList(props: BeforeVoteListProps) { }); }; - const handleClickVote = () => { - if (!isLogin) { - toggleLoginModal(); - return; - } - - if (currentIdx !== "") { - handlePost(); - mutateBallotState(); - } - }; - - const handlePost = () => { + const handlePostVote = () => { + if (currentIdx === "") return; voteApi.postVote({ ballotTopicId: ballotTopic.ballotTopic._id, ballotItemId: currentIdx }); + mutateBallotState(); }; return ( @@ -59,18 +43,9 @@ export default function BeforeVoteList(props: BeforeVoteListProps) { ))} - + 투표하기 - - {isLoginModalOpen && ( - - )} ); } diff --git a/src/@components/VotePage/hooks/useBallotTopic.ts b/src/@components/VotePage/hooks/useBallotTopic.ts index bd92ff9a..ae7b4d9c 100644 --- a/src/@components/VotePage/hooks/useBallotTopic.ts +++ b/src/@components/VotePage/hooks/useBallotTopic.ts @@ -7,9 +7,13 @@ import { BallotTopicData } from "../../../types/ballots"; import { PiickleSWRResponse } from "../../../types/remote/swr"; export default function useBallotTopic(ballotId: string) { - const { data } = useSWR>(`${PATH.BALLOTS}/${ballotId}`, realReq.GET_SWR, { - suspense: true, - }); + const { data } = useSWR>( + `${PATH.BALLOTS}/${ballotId}`, + (url) => realReq.GET_SWR(url, { withCredentials: true }), + { + suspense: true, + }, + ); const { mutate } = useSWRConfig(); const [isBeforeVotingState, setIsBeforeVotingState] = useState(true); diff --git a/src/core/api/common/axios.ts b/src/core/api/common/axios.ts index 4385f72b..25d2d3d2 100644 --- a/src/core/api/common/axios.ts +++ b/src/core/api/common/axios.ts @@ -1,16 +1,15 @@ -import axios from "axios"; +import axios, { AxiosRequestConfig } from "axios"; export const axiosInstance = axios.create({ baseURL: import.meta.env.VITE_BASE_URL, headers: { "Content-Type": "application/json", }, - // withCredentials: true, }); export const realReq = { - GET_SWR(path: string) { - return axiosInstance.get(path); + GET_SWR(path: string, option?: AxiosRequestConfig) { + return axiosInstance.get(path, option); }, async GET(path: string, option?: { params: string }) { @@ -18,8 +17,8 @@ export const realReq = { return data.data; }, - async POST(path: string, body: T) { - const data = await axiosInstance.post(path, body); + async POST(path: string, body: T, option?: AxiosRequestConfig) { + const data = await axiosInstance.post(path, body, option); return data.data; }, diff --git a/src/core/api/vote.ts b/src/core/api/vote.ts index fbe20008..d5c683e1 100644 --- a/src/core/api/vote.ts +++ b/src/core/api/vote.ts @@ -3,7 +3,7 @@ import { realReq } from "./common/axios"; import { PATH } from "./common/constants"; function postVote(postingVote: PostingVote) { - return realReq.POST(PATH.BALLOTS, postingVote); + return realReq.POST(PATH.BALLOTS, postingVote, { withCredentials: true }); } export const voteApi = {