diff --git a/client/src/api/axios.ts b/client/src/api/axios.ts index a42fe30e..f2ad4074 100644 --- a/client/src/api/axios.ts +++ b/client/src/api/axios.ts @@ -1,12 +1,4 @@ -import axios, { - AxiosRequestConfig, - AxiosResponse, - InternalAxiosRequestConfig, -} from 'axios'; - -import useUserStore from '@/stores/userStore'; - -const { setAccessToken } = useUserStore(); +import axios, { AxiosResponse } from 'axios'; const accessToken = typeof window !== 'undefined' @@ -18,7 +10,7 @@ const refreshToken = ? JSON.parse(localStorage.getItem('user-key') as string).state.refreshToken : null; -const instance = axios.create({ +export const instance = axios.create({ baseURL: process.env.NEXT_PUBLIC_API_URL, headers: { Authorization: accessToken, @@ -27,7 +19,8 @@ const instance = axios.create({ withCredentials: true, }); -// atob을 활용한 JWT 디코딩 +const storageData = JSON.parse(localStorage.getItem('user-key') as string); + const parseJWT = (token: string | null) => { if (token) return JSON.parse(atob(token.split('.')[1])); }; @@ -36,27 +29,28 @@ const authVerify = () => { const decodedAccess = parseJWT(accessToken); const decodedRefresh = parseJWT(refreshToken); - if (decodedAccess.exp * 1000 < Date.now()) { + if (decodedAccess?.exp * 1000 < Date.now()) { return 'Access Token Expired'; } - if (decodedRefresh.exp * 1000 < Date.now()) { + if (decodedRefresh?.exp * 1000 < Date.now()) { return 'Refresh Token Expired'; } return true; }; -// 응답 받기 전, 새로운 accessToke이 존재하면 바꿔주기 -export const onFulfiled = async (response: AxiosResponse) => { +const onFulfiled = async (response: AxiosResponse) => { if (authVerify() === 'Access Token Expired') { - const { authorization: newAccessToken } = response.headers; + const { authorization: newAccessToken } = response?.headers; + + storageData.state.accessToken = newAccessToken; - setAccessToken(newAccessToken); + localStorage.setItem('user-key', JSON.stringify(storageData)); - // 타입 호환을 위해 새로운 객체를 만들어서 업데이트하기 response.config.headers = Object.assign({}, response.config.headers, { authorization: `${newAccessToken}`, + refresh: refreshToken ?? '', }); return await axios(response.config); @@ -66,9 +60,7 @@ export const onFulfiled = async (response: AxiosResponse) => { }; instance.interceptors.request.use( - //! AxiosRequestConfig 대신 InternalAxiosRequestConfig를 사용하라고 하는데... - // InternalAxiosRequestConfig를 개발자가 직접 건드는게 좋은건 아니라고 하던데 흠... - async (config: InternalAxiosRequestConfig) => { + async (config) => { config.headers = config.headers ?? {}; if (accessToken) { diff --git a/client/src/api/history.ts b/client/src/api/history.ts index 9232bfcf..a3f14fcc 100644 --- a/client/src/api/history.ts +++ b/client/src/api/history.ts @@ -1,32 +1,13 @@ -import axios from 'axios'; - -const accessToken = - typeof window !== 'undefined' - ? JSON.parse(localStorage.getItem('user-key') as string).state.accessToken - : null; - -const refreshToken = - typeof window !== 'undefined' - ? JSON.parse(localStorage.getItem('user-key') as string).state.refreshToken - : null; - -export const historyAxios = axios.create({ - baseURL: process.env.NEXT_PUBLIC_API_URL, - headers: { - Authorization: accessToken, - Refresh: refreshToken, - }, - withCredentials: true, -}); +import { instance } from './axios'; export const getUserInfo = async (id: string) => { - const { data } = await historyAxios.get(`/accounts/${id}`); + const { data } = await instance.get(`/accounts/${id}`); return data; }; export const postUserPassword = async (password: string) => { - const { data, headers } = await historyAxios.post( + const { data, headers } = await instance.post( `/accounts/password/verification`, { password, @@ -37,13 +18,13 @@ export const postUserPassword = async (password: string) => { }; export const deleteUser = async () => { - const { status } = await historyAxios.delete(`/accounts`); + const { status } = await instance.delete(`/accounts`); return status; }; export const getBoardWrittenByPage = async ({ pageParam = 1 }, id: string) => { - const response = await historyAxios + const response = await instance .get(`/accounts/boardWritten/${id}?page=${pageParam}`) .then((response) => response.data); @@ -51,7 +32,7 @@ export const getBoardWrittenByPage = async ({ pageParam = 1 }, id: string) => { }; export const getBoardLikedByPage = async ({ pageParam = 1 }, id: string) => { - const response = await historyAxios + const response = await instance .get(`/accounts/boardLiked/${id}?page=${pageParam}`) .then((response) => response.data); @@ -62,7 +43,7 @@ export const getCommentWrittenByPage = async ( { pageParam = 1 }, id: string, ) => { - const response = await historyAxios + const response = await instance .get(`/accounts/commentWritten/${id}?page=${pageParam}`) .then((response) => response.data); diff --git a/client/src/api/profile.ts b/client/src/api/profile.ts index 7d1d379f..5cd02f0f 100644 --- a/client/src/api/profile.ts +++ b/client/src/api/profile.ts @@ -1,26 +1,7 @@ -import axios from 'axios'; - -const accessToken = - typeof window !== 'undefined' - ? JSON.parse(localStorage.getItem('user-key') as string).state.accessToken - : null; - -const refreshToken = - typeof window !== 'undefined' - ? JSON.parse(localStorage.getItem('user-key') as string).state.refreshToken - : null; - -export const historyAxios = axios.create({ - baseURL: process.env.NEXT_PUBLIC_API_URL, - headers: { - Authorization: accessToken, - Refresh: refreshToken, - }, - withCredentials: true, -}); +import { instance } from './axios'; export const updateUserNickname = async (displayName: string) => { - const { data, headers, status } = await historyAxios.patch( + const { data, headers, status } = await instance.patch( `/accounts/displayname`, { displayName, @@ -34,13 +15,10 @@ export const updateUserPassword = async ( presentPassword: string, changedPassword: string, ) => { - const { data, headers, status } = await historyAxios.patch( - `/accounts/password`, - { - presentPassword, - changedPassword, - }, - ); + const { data, headers, status } = await instance.patch(`/accounts/password`, { + presentPassword, + changedPassword, + }); return { data, headers, status }; }; @@ -53,15 +31,11 @@ export const updateUserProfileImage = async (file: File) => { const formData = new FormData(); formData.append('profileImage', file); - const response = await historyAxios.patch( - `/accounts/profileimage`, - formData, - { - headers: { - 'Content-Type': 'multipart/form-data', - }, + const response = await instance.patch(`/accounts/profileimage`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', }, - ); + }); return response.data; }; diff --git a/client/src/components/history/ConfirmModal.tsx b/client/src/components/history/ConfirmModal.tsx index 36918084..f9edfbee 100644 --- a/client/src/components/history/ConfirmModal.tsx +++ b/client/src/components/history/ConfirmModal.tsx @@ -1,11 +1,11 @@ 'use client'; -import useDeleteUser from '@/hooks/mutation/useDeleteUser'; +import useDeleteUserMutation from '@/hooks/mutation/useDeleteUserMutation'; import { CommonButton, Modal, ModalPortal } from '../common'; export default function ConfirmModal() { - const { onDeleteUser, close } = useDeleteUser(); + const { mutate: onDeleteUser, close } = useDeleteUserMutation(); return ( diff --git a/client/src/components/history/HistoryBoard.tsx b/client/src/components/history/HistoryBoard.tsx index 1d33e9c4..c6064c8f 100644 --- a/client/src/components/history/HistoryBoard.tsx +++ b/client/src/components/history/HistoryBoard.tsx @@ -3,12 +3,10 @@ import { useRouter } from 'next/navigation'; import InfiniteScroll from 'react-infinite-scroller'; -import useUserStore from '@/stores/userStore'; - -import useHistoryBoard from '@/hooks/useHistoryBoard'; +import useHistoryBoardQuery from '@/hooks/query/useHistoryBoardQuery'; import { HistoryPostCard } from '.'; -import EmptyDiary from '../leaf/EmptyDiary'; +import { EmptyDiary } from '../leaf'; import { ErrorMessage, LoadingMessage } from '../common'; import { HistoryBoradProps } from '@/types/common'; @@ -16,15 +14,13 @@ import { HistoryBoradProps } from '@/types/common'; export default function HistoryBoard({ paramsId }: HistoryBoradProps) { const router = useRouter(); - const { userId } = useUserStore(); - const { data: boards, fetchNextPage, hasNextPage, isLoading, isError, - } = useHistoryBoard(paramsId); + } = useHistoryBoardQuery(paramsId); const likesAmount = (likes: []) => { if (likes?.length === 0) return 0; @@ -41,8 +37,6 @@ export default function HistoryBoard({ paramsId }: HistoryBoradProps) { key={index} className="w-[715px] my-4 max-[730px]:w-[512px] max-[630px]:w-[312px] flex justify-center items-center ml-1"> { if (likes?.length === 0) return 0; @@ -41,8 +37,6 @@ export default function HistoryComment({ paramsId }: HistoryBoradProps) { key={index} className="w-[715px] my-4 max-[730px]:w-[512px] max-[630px]:w-[312px] flex justify-center items-center ml-1"> diff --git a/client/src/components/history/HistoryLikes.tsx b/client/src/components/history/HistoryLikes.tsx index a50b70d7..8437ba0d 100644 --- a/client/src/components/history/HistoryLikes.tsx +++ b/client/src/components/history/HistoryLikes.tsx @@ -3,12 +3,10 @@ import { useRouter } from 'next/navigation'; import InfiniteScroll from 'react-infinite-scroller'; -import useHistoryLikes from '@/hooks/useHistoryLikes'; - -import useUserStore from '@/stores/userStore'; +import useHistoryLikesQuery from '@/hooks/query/useHistoryLikesQuery'; import { HistoryPostCard } from '.'; -import EmptyDiary from '../leaf/EmptyDiary'; +import { EmptyDiary } from '../leaf'; import { ErrorMessage, LoadingMessage } from '../common'; import { HistoryBoradProps } from '@/types/common'; @@ -16,15 +14,13 @@ import { HistoryBoradProps } from '@/types/common'; export default function HistoryLikes({ paramsId }: HistoryBoradProps) { const router = useRouter(); - const { userId } = useUserStore(); - const { data: likes, fetchNextPage, hasNextPage, isLoading, isError, - } = useHistoryLikes(paramsId); + } = useHistoryLikesQuery(paramsId); const likesAmount = (likes: []) => { if (likes?.length === 0) return 0; @@ -41,8 +37,6 @@ export default function HistoryLikes({ paramsId }: HistoryBoradProps) { key={index} className="w-[715px] my-4 max-[730px]:w-[512px] max-[630px]:w-[312px] flex justify-center items-center ml-1"> diff --git a/client/src/components/history/ResignModal.tsx b/client/src/components/history/ResignModal.tsx index 00f24111..ef8ea92e 100644 --- a/client/src/components/history/ResignModal.tsx +++ b/client/src/components/history/ResignModal.tsx @@ -2,7 +2,7 @@ import { useForm } from 'react-hook-form'; -import useResignCheck from '@/hooks/useResignCheck'; +import useResignCheckMutation from '@/hooks/mutation/useResignCheckMutation'; import { SignModalInput } from '../sign'; import { CommonButton, Modal, ModalPortal } from '../common'; @@ -17,7 +17,7 @@ export default function ResignModal() { formState: { errors, isSubmitting }, } = useForm(); - const { onPasswordCheck, close } = useResignCheck(); + const { mutate: onPasswordCheck, close } = useResignCheckMutation(); const userPassword = watch('password'); diff --git a/client/src/components/history/UserInfo.tsx b/client/src/components/history/UserInfo.tsx index 5d7724b6..3f04ca86 100644 --- a/client/src/components/history/UserInfo.tsx +++ b/client/src/components/history/UserInfo.tsx @@ -6,7 +6,7 @@ import { useRouter } from 'next/navigation'; import useUserStore from '@/stores/userStore'; import useClient from '@/hooks/useClient'; -import useUserInfo from '@/hooks/useUserInfo'; +import useUserInfoQuery from '@/hooks/query/useUserInfoQuery'; import { CommonButton } from '../common'; @@ -22,7 +22,7 @@ export default function UserInfo({ paramsId }: HistoryUserProps) { const { userId } = useUserStore(); const isClient = useClient(); - const { profileImageUrl, displayName, grade, point } = useUserInfo(id); + const { profileImageUrl, displayName, grade, point } = useUserInfoQuery(id); return (
diff --git a/client/src/components/profile/ImageForm.tsx b/client/src/components/profile/ImageForm.tsx index 4a45c350..6b24df5f 100644 --- a/client/src/components/profile/ImageForm.tsx +++ b/client/src/components/profile/ImageForm.tsx @@ -3,7 +3,7 @@ import Image from 'next/image'; import useClient from '@/hooks/useClient'; -import useChangeImage from '@/hooks/useChangeImage'; +import useChangeImageMutation from '@/hooks/mutation/useChangeImageMutation'; import { CommonButton } from '../common'; @@ -18,7 +18,7 @@ export default function ImageForm({ className }: DefaultProps) { onImageChange, onImageSubmit, - } = useChangeImage(); + } = useChangeImageMutation(); return ( <> diff --git a/client/src/components/profile/NicknameForm.tsx b/client/src/components/profile/NicknameForm.tsx index 9ec0e3bc..629beb19 100644 --- a/client/src/components/profile/NicknameForm.tsx +++ b/client/src/components/profile/NicknameForm.tsx @@ -3,7 +3,7 @@ import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import useChangeNickname from '@/hooks/useChangeNickname'; +import useChangeNicknameMutation from '@/hooks/mutation/useChangeNicknameMutation'; import { CommonButton, TextInput } from '../common'; @@ -18,7 +18,7 @@ export default function NicknameForm() { setValue, } = useForm(); - const { updateNickName, displayName } = useChangeNickname(); + const { updateNickName, displayName } = useChangeNicknameMutation(); const nickname = watch('nickname'); diff --git a/client/src/components/profile/PasswordForm.tsx b/client/src/components/profile/PasswordForm.tsx index 7ed55174..eeeee588 100644 --- a/client/src/components/profile/PasswordForm.tsx +++ b/client/src/components/profile/PasswordForm.tsx @@ -2,7 +2,7 @@ import { useForm } from 'react-hook-form'; -import useChangePassword from '@/hooks/useChagnePassword'; +import useChangePasswordMutation from '@/hooks/mutation/useChangePasswordMutation'; import { CommonButton, PasswordInput } from '../common'; @@ -19,7 +19,7 @@ export default function PasswordForm() { const presentPassword = watch('password'); const changedPassword = watch('newPasswordCheck'); - const { updatePassword } = useChangePassword( + const { updatePassword } = useChangePasswordMutation( presentPassword, changedPassword, ); diff --git a/client/src/components/signin/SigninForm.tsx b/client/src/components/signin/SigninForm.tsx index d8f2ecac..b7bbb4a0 100644 --- a/client/src/components/signin/SigninForm.tsx +++ b/client/src/components/signin/SigninForm.tsx @@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form'; import useModalStore from '@/stores/modalStore'; -import useSignin from '@/hooks/useSignIn'; +import useSigninMutation from '@/hooks/mutation/useSigninMutation'; import { SignPasswordInput, SignInput } from '../sign'; import { CommonButton } from '../common'; @@ -21,7 +21,7 @@ export default function SigninForm() { const { open, changeType } = useModalStore(); - const { onSiginIn } = useSignin(); + const { mutate: onSiginIn } = useSigninMutation(); const email = watch('email'); const password = watch('password'); diff --git a/client/src/components/signup/SignupForm.tsx b/client/src/components/signup/SignupForm.tsx index 3be097d0..874c13d0 100644 --- a/client/src/components/signup/SignupForm.tsx +++ b/client/src/components/signup/SignupForm.tsx @@ -5,8 +5,8 @@ import { useForm } from 'react-hook-form'; import useModalStore from '@/stores/modalStore'; import useSignStore from '@/stores/signStore'; -import useAuthEmail from '@/hooks/useAuthEmail'; -import useSignup from '@/hooks/useSignup'; +import useAuthEmailMutation from '@/hooks/mutation/useAuthEmailMutation'; +import useSignupMutation from '@/hooks/mutation/useSignupMutation'; import useEffectOnce from '@/hooks/useEffectOnce'; import { SignInput, SignPasswordInput } from '../sign'; @@ -25,8 +25,8 @@ export default function SignupForm() { const { changeType, open } = useModalStore(); const { isCode, setIsCode } = useSignStore(); - const { sendCodeWithEmail } = useAuthEmail(); - const { onSignup } = useSignup(); + const { mutate: sendCodeWithEmail } = useAuthEmailMutation(); + const { mutate: onSignup } = useSignupMutation(); const email = watch('email'); const password = watch('password'); diff --git a/client/src/hooks/useAuthEmail.ts b/client/src/hooks/mutation/useAuthEmailMutation.ts similarity index 68% rename from client/src/hooks/useAuthEmail.ts rename to client/src/hooks/mutation/useAuthEmailMutation.ts index e2b78e18..2077ed26 100644 --- a/client/src/hooks/useAuthEmail.ts +++ b/client/src/hooks/mutation/useAuthEmailMutation.ts @@ -4,16 +4,16 @@ import { sendCodeByEmail } from '@/api/user'; import useSignStore from '@/stores/signStore'; -const useAuthEmail = () => { +const useAuthEmailMutation = () => { const { setCode, isCode } = useSignStore(); - const { mutate: sendCodeWithEmail } = useMutation({ + const { mutate } = useMutation({ mutationFn: (email: string) => sendCodeByEmail(email), onSuccess(data) { setCode(data.data.data.authCode); }, }); - return { sendCodeWithEmail, isCode }; + return { mutate, isCode }; }; -export default useAuthEmail; +export default useAuthEmailMutation; diff --git a/client/src/hooks/useChangeImage.ts b/client/src/hooks/mutation/useChangeImageMutation.ts similarity index 84% rename from client/src/hooks/useChangeImage.ts rename to client/src/hooks/mutation/useChangeImageMutation.ts index 96698635..dd99267e 100644 --- a/client/src/hooks/useChangeImage.ts +++ b/client/src/hooks/mutation/useChangeImageMutation.ts @@ -10,9 +10,8 @@ import { ALERT_TEXT } from '@/constants/contents'; import isValidFileSize from '@/utils/isValidFileSize'; -const useChangeImage = () => { - const { profileImageUrl, setProfileImageUrl, setAccessToken } = - useUserStore(); +const useChangeImageMutation = () => { + const { profileImageUrl, setProfileImageUrl } = useUserStore(); const { changeType, open } = useModalStore(); const imageUploadRef = useRef(null); @@ -20,7 +19,7 @@ const useChangeImage = () => { const [imageUrl, setImageUrl] = useState(profileImageUrl); const [isDisabled, setIsDisabled] = useState(true); - const { mutate: changeImage } = useMutation({ + const { mutate } = useMutation({ mutationFn: (image: FileList) => updateUserProfileImage(image[0]), onSuccess: (data) => { @@ -29,8 +28,6 @@ const useChangeImage = () => { changeType('ChangeImageModal'); open(); - - setAccessToken(data.headers?.authorization); }, }); @@ -57,7 +54,7 @@ const useChangeImage = () => { const onImageSubmit = async () => { if (image && !isDisabled) { - changeImage(image); + mutate(image); } }; @@ -70,4 +67,4 @@ const useChangeImage = () => { }; }; -export default useChangeImage; +export default useChangeImageMutation; diff --git a/client/src/hooks/useChangeNickname.ts b/client/src/hooks/mutation/useChangeNicknameMutation.ts similarity index 72% rename from client/src/hooks/useChangeNickname.ts rename to client/src/hooks/mutation/useChangeNicknameMutation.ts index 81dc9194..43697cee 100644 --- a/client/src/hooks/useChangeNickname.ts +++ b/client/src/hooks/mutation/useChangeNicknameMutation.ts @@ -8,18 +8,17 @@ import useModalStore from '@/stores/modalStore'; import { InputValues } from '@/types/common'; -const useChangeNickname = () => { +const useChangeNicknameMutation = () => { const { reset } = useForm(); - const { setAccessToken, setDisplayName, displayName } = useUserStore(); + const { setDisplayName, displayName } = useUserStore(); const { changeType, open } = useModalStore(); - const { mutate: onChangeNickname } = useMutation({ + const { mutate } = useMutation({ mutationFn: (nickname: string) => updateUserNickname(nickname), onSuccess: (data, nickname) => { setDisplayName(nickname); - setAccessToken(data.headers?.authorization); reset(); @@ -31,10 +30,10 @@ const useChangeNickname = () => { const updateNickName = async (nickname: string) => { if (!nickname) return; - onChangeNickname(nickname); + mutate(nickname); }; return { updateNickName, displayName }; }; -export default useChangeNickname; +export default useChangeNicknameMutation; diff --git a/client/src/hooks/useChagnePassword.ts b/client/src/hooks/mutation/useChangePasswordMutation.ts similarity index 75% rename from client/src/hooks/useChagnePassword.ts rename to client/src/hooks/mutation/useChangePasswordMutation.ts index f1f020bf..7e9a89ed 100644 --- a/client/src/hooks/useChagnePassword.ts +++ b/client/src/hooks/mutation/useChangePasswordMutation.ts @@ -3,28 +3,24 @@ import { useMutation } from '@tanstack/react-query'; import { updateUserPassword } from '@/api/profile'; -import useUserStore from '@/stores/userStore'; import useModalStore from '@/stores/modalStore'; import { InputValues } from '@/types/common'; import { ALERT_TEXT } from '@/constants/contents'; -const useChangePassword = ( +const useChangePasswordMutation = ( presentPassword: string, changedPassword: string, ) => { const { reset } = useForm(); const { changeType, open } = useModalStore(); - const { setAccessToken } = useUserStore(); - const { mutate: changePassword } = useMutation({ + const { mutate } = useMutation({ mutationFn: () => updateUserPassword(presentPassword, changedPassword), onSuccess: (data) => { - setAccessToken(data.headers?.authorization); - changeType('ChangePasswordModal'); open(); }, @@ -38,11 +34,11 @@ const useChangePassword = ( return; } - changePassword(); + mutate(); reset(); }; return { updatePassword }; }; -export default useChangePassword; +export default useChangePasswordMutation; diff --git a/client/src/hooks/mutation/useDeleteUser.ts b/client/src/hooks/mutation/useDeleteUserMutation.ts similarity index 69% rename from client/src/hooks/mutation/useDeleteUser.ts rename to client/src/hooks/mutation/useDeleteUserMutation.ts index e58345cc..b8630371 100644 --- a/client/src/hooks/mutation/useDeleteUser.ts +++ b/client/src/hooks/mutation/useDeleteUserMutation.ts @@ -4,17 +4,17 @@ import { deleteUser } from '@/api/history'; import useModalStore from '@/stores/modalStore'; -const useDeleteUser = () => { +const useDeleteUserMutation = () => { const { close, changeType } = useModalStore(); - const { mutate: onDeleteUser } = useMutation({ + const { mutate } = useMutation({ mutationFn: () => deleteUser(), onSuccess: () => { return changeType('SuccessedModal'); }, }); - return { onDeleteUser, close }; + return { mutate, close }; }; -export default useDeleteUser; +export default useDeleteUserMutation; diff --git a/client/src/hooks/useResignCheck.ts b/client/src/hooks/mutation/useResignCheckMutation.ts similarity index 55% rename from client/src/hooks/useResignCheck.ts rename to client/src/hooks/mutation/useResignCheckMutation.ts index 3f66a079..1bd6f62a 100644 --- a/client/src/hooks/useResignCheck.ts +++ b/client/src/hooks/mutation/useResignCheckMutation.ts @@ -3,24 +3,22 @@ import { useMutation } from '@tanstack/react-query'; import { postUserPassword } from '@/api/history'; import useModalStore from '@/stores/modalStore'; -import useUserStore from '@/stores/userStore'; -const useResignCheck = () => { - const { setAccessToken } = useUserStore(); +const useResignCheckMutation = () => { const { changeType, close } = useModalStore(); - const { mutate: onPasswordCheck } = useMutation({ + const { mutate } = useMutation({ mutationFn: (userPassword: string) => postUserPassword(userPassword), onSuccess: (data) => { if (!data.data.data) { return changeType('FailureModal'); } - changeType('ConfirmModal'), setAccessToken(data.headers?.authorization); + changeType('ConfirmModal'); }, }); - return { onPasswordCheck, close }; + return { mutate, close }; }; -export default useResignCheck; +export default useResignCheckMutation; diff --git a/client/src/hooks/useSignIn.ts b/client/src/hooks/mutation/useSigninMutation.ts similarity index 91% rename from client/src/hooks/useSignIn.ts rename to client/src/hooks/mutation/useSigninMutation.ts index 9dbdf079..34213f5e 100644 --- a/client/src/hooks/useSignIn.ts +++ b/client/src/hooks/mutation/useSigninMutation.ts @@ -11,7 +11,7 @@ import { SigninFormValue } from '@/types/common'; import { ALERT_TEXT } from '@/constants/contents'; -const useSignin = () => { +const useSigninMutation = () => { const router = useRouter(); const { reset } = useForm(); @@ -19,7 +19,7 @@ const useSignin = () => { const { setEmailUser } = useUserStore(); const { getSigninForm, getSignupForm } = useSignStore(); - const { mutate: onSiginIn } = useMutation({ + const { mutate } = useMutation({ mutationFn: ({ email, password }: SigninFormValue) => postUserInfo(email, password), @@ -57,7 +57,7 @@ const useSignin = () => { }, }); - return { onSiginIn }; + return { mutate }; }; -export default useSignin; +export default useSigninMutation; diff --git a/client/src/hooks/useSignup.ts b/client/src/hooks/mutation/useSignupMutation.ts similarity index 85% rename from client/src/hooks/useSignup.ts rename to client/src/hooks/mutation/useSignupMutation.ts index e2341a6a..ba1d45a3 100644 --- a/client/src/hooks/useSignup.ts +++ b/client/src/hooks/mutation/useSignupMutation.ts @@ -8,14 +8,14 @@ import useSignStore from '@/stores/signStore'; import { SignupFormValue } from '@/types/common'; -const useSignup = () => { +const useSignupMutation = () => { const router = useRouter(); const { reset } = useForm(); const { getSigninForm, getSignupForm, setIsCode } = useSignStore(); - const { mutate: onSignup } = useMutation({ + const { mutate } = useMutation({ mutationFn: ({ email, password, nickname }: SignupFormValue) => postCreateUser(email, password, nickname as string), @@ -30,7 +30,7 @@ const useSignup = () => { }, }); - return { onSignup }; + return { mutate }; }; -export default useSignup; +export default useSignupMutation; diff --git a/client/src/hooks/useHistoryBoard.ts b/client/src/hooks/query/useHistoryBoardQuery.ts similarity index 87% rename from client/src/hooks/useHistoryBoard.ts rename to client/src/hooks/query/useHistoryBoardQuery.ts index fccf9db5..80971b23 100644 --- a/client/src/hooks/useHistoryBoard.ts +++ b/client/src/hooks/query/useHistoryBoardQuery.ts @@ -2,7 +2,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'; import { getBoardWrittenByPage } from '@/api/history'; -const useHistoryBoard = (paramsId: string) => { +const useHistoryBoardQuery = (paramsId: string) => { const { data, fetchNextPage, hasNextPage, isLoading, isError } = useInfiniteQuery( ['boardWritten'], @@ -26,4 +26,4 @@ const useHistoryBoard = (paramsId: string) => { }; }; -export default useHistoryBoard; +export default useHistoryBoardQuery; diff --git a/client/src/hooks/useHistoryComment.ts b/client/src/hooks/query/useHistoryCommentQuery.ts similarity index 87% rename from client/src/hooks/useHistoryComment.ts rename to client/src/hooks/query/useHistoryCommentQuery.ts index 9b8911e8..9d50f820 100644 --- a/client/src/hooks/useHistoryComment.ts +++ b/client/src/hooks/query/useHistoryCommentQuery.ts @@ -2,7 +2,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'; import { getCommentWrittenByPage } from '@/api/history'; -const useHistoryComment = (paramsId: string) => { +const useHistoryCommentQuery = (paramsId: string) => { const { data, fetchNextPage, hasNextPage, isLoading, isError } = useInfiniteQuery( ['commentWritten'], @@ -25,4 +25,4 @@ const useHistoryComment = (paramsId: string) => { }; }; -export default useHistoryComment; +export default useHistoryCommentQuery; diff --git a/client/src/hooks/useHistoryLikes.ts b/client/src/hooks/query/useHistoryLikesQuery.ts similarity index 88% rename from client/src/hooks/useHistoryLikes.ts rename to client/src/hooks/query/useHistoryLikesQuery.ts index c02e7acb..f508ac80 100644 --- a/client/src/hooks/useHistoryLikes.ts +++ b/client/src/hooks/query/useHistoryLikesQuery.ts @@ -2,7 +2,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'; import { getBoardLikedByPage } from '@/api/history'; -const useHistoryLikes = (paramsId: string) => { +const useHistoryLikesQuery = (paramsId: string) => { const { data, fetchNextPage, hasNextPage, isLoading, isError } = useInfiniteQuery( ['boardLiked'], @@ -27,4 +27,4 @@ const useHistoryLikes = (paramsId: string) => { }; }; -export default useHistoryLikes; +export default useHistoryLikesQuery; diff --git a/client/src/hooks/useUserInfo.ts b/client/src/hooks/query/useUserInfoQuery.ts similarity index 86% rename from client/src/hooks/useUserInfo.ts rename to client/src/hooks/query/useUserInfoQuery.ts index b774ec29..74124f4a 100644 --- a/client/src/hooks/useUserInfo.ts +++ b/client/src/hooks/query/useUserInfoQuery.ts @@ -6,7 +6,7 @@ import { getUserInfo } from '@/api/history'; import useHistoryStore from '@/stores/historyStore'; -const useUserInfo = (id: string) => { +const useUserInfoQuery = (id: string) => { const { setHistoryUser, profileImageUrl, displayName, grade, point } = useHistoryStore(); @@ -19,4 +19,4 @@ const useUserInfo = (id: string) => { return { profileImageUrl, displayName, grade, point }; }; -export default useUserInfo; +export default useUserInfoQuery; diff --git a/client/src/hooks/useFindPassword.ts b/client/src/hooks/useFindPassword.ts index adc9c129..dcb3bf90 100644 --- a/client/src/hooks/useFindPassword.ts +++ b/client/src/hooks/useFindPassword.ts @@ -14,7 +14,7 @@ const useFindPassword = () => { queryFn: () => getUsersEmail(), }); - const { mutate: temporaryPassword } = useMutation({ + const { mutate } = useMutation({ mutationFn: (email: string) => sendTemporaryPasswordByEmail(email), onSuccess: () => { @@ -31,7 +31,7 @@ const useFindPassword = () => { if (!existEmail) return changeType('FailureModal'); - temporaryPassword(userEmail); + mutate(userEmail); return changeType('SuccessedModal'); }; diff --git a/client/src/stores/userStore.ts b/client/src/stores/userStore.ts index baabccc4..955e3870 100644 --- a/client/src/stores/userStore.ts +++ b/client/src/stores/userStore.ts @@ -15,8 +15,6 @@ interface UserInfo { isGoogleLogin?: boolean; } interface User extends UserInfo { - setAccessToken: (accessToken: string) => void; - setGoogleUser: (userInfo: UserInfo) => void; setEmailUser: (userInfo: UserInfo) => void; @@ -39,10 +37,6 @@ const useUserStore = create( displayName: '', profileImageUrl: '', - setAccessToken: (accessToken) => { - set({ accessToken }); - }, - setGoogleUser: (userInfo: UserInfo) => { const { accessToken,