From dbb67d03e0a4ac967b05996398b1302ab39dd821 Mon Sep 17 00:00:00 2001
From: Jungu Lee <1zzangjun@gmail.com>
Date: Sun, 3 Dec 2023 14:30:00 +0900
Subject: [PATCH] =?UTF-8?q?Refactor=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8/?=
=?UTF-8?q?=EC=95=84=EC=9B=83=20=EB=AE=A4=ED=85=8C=EC=9D=B4=EC=85=98=20?=
=?UTF-8?q?=EC=B1=85=EC=9E=84=EB=B6=84=EB=A6=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/app/(protectedRoute)/user/setting/page.tsx | 13 +++++++++++--
client/src/components/user/signin/SigninForm.tsx | 11 +++++++----
client/src/queries/auth/useLoginMutation.tsx | 3 +--
client/src/queries/auth/useLogoutMutation.tsx | 7 +------
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/client/src/app/(protectedRoute)/user/setting/page.tsx b/client/src/app/(protectedRoute)/user/setting/page.tsx
index a5be0e9..0901cd6 100644
--- a/client/src/app/(protectedRoute)/user/setting/page.tsx
+++ b/client/src/app/(protectedRoute)/user/setting/page.tsx
@@ -13,10 +13,13 @@ import {
} from "@mui/material";
import PostSeeMoreIcon from "@/assets/icons/PostSeeMoreIcon.svg";
import useLogoutMutation from "@/queries/auth/useLogoutMutation";
+import { useRouter } from "next/navigation";
+import HOME from "@/const/clientPath";
const SettingPage = () => {
const { data: myInfo } = useMyInfoQuery();
- const { mutate: logoutHandler } = useLogoutMutation();
+ const { mutateAsync: logoutHandler } = useLogoutMutation();
+ const router = useRouter();
return (
<>
@@ -67,7 +70,13 @@ const SettingPage = () => {
계정
-
diff --git a/client/src/components/user/signin/SigninForm.tsx b/client/src/components/user/signin/SigninForm.tsx
index 48b42ca..84fad87 100644
--- a/client/src/components/user/signin/SigninForm.tsx
+++ b/client/src/components/user/signin/SigninForm.tsx
@@ -1,23 +1,26 @@
"use client";
import useLoginMutation from "@/queries/auth/useLoginMutation";
import { Box, Button, TextField, Typography } from "@mui/material";
-
+import { useRouter } from "next/navigation";
import { useState } from "react";
+import HOME from "@/const/clientPath";
const SigninForm = () => {
const [id, setId] = useState("");
const [password, setPassword] = useState("");
- const { mutate: loginMutation, isError } = useLoginMutation();
+ const { mutateAsync: loginMutation, isError } = useLoginMutation();
+ const router = useRouter();
return (
{
+ onSubmit={async (event) => {
event.preventDefault();
if (!id || !password) {
return;
}
- loginMutation({ id, password });
+ await loginMutation({ id, password });
+ router.push(HOME)
}}
sx={{ mt: 1 }}
>
diff --git a/client/src/queries/auth/useLoginMutation.tsx b/client/src/queries/auth/useLoginMutation.tsx
index 226a510..cfcb7dc 100644
--- a/client/src/queries/auth/useLoginMutation.tsx
+++ b/client/src/queries/auth/useLoginMutation.tsx
@@ -4,7 +4,6 @@ import { SigninRequirement } from "@/types/auth/signinRequirement";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { MyInfoQueryKeys } from "./useMyInfoQuery";
import { useRouter } from "next/navigation";
-import HOME from "@/const/clientPath";
import { useErrorHandler } from "@/utils/errorHandler";
import { useGlobalLoadingStore } from "@/store/useGlobalLoadingStore";
@@ -26,7 +25,7 @@ const useLoginMutation = () => {
onSuccess: async ({ token }) => {
localStorage?.setItem("accessToken", token);
queryClient.invalidateQueries({ queryKey: MyInfoQueryKeys.all });
- router.push(HOME);
+ router.refresh();
},
onError: (error) => errorHandler(error),
onSettled: () => {
diff --git a/client/src/queries/auth/useLogoutMutation.tsx b/client/src/queries/auth/useLogoutMutation.tsx
index 0f23249..e852265 100644
--- a/client/src/queries/auth/useLogoutMutation.tsx
+++ b/client/src/queries/auth/useLogoutMutation.tsx
@@ -1,7 +1,5 @@
-import HOME from "@/const/clientPath";
import { LOGOUT_BFF } from "@/const/serverPath";
import { axiosBff } from "@/libs/axios";
-import { useGlobalSnackbarStore } from "@/store/useGlobalSnackbarStore";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useRouter } from "next/navigation";
@@ -9,15 +7,12 @@ const useLogoutMutation = () => {
const router = useRouter();
const queryClient = useQueryClient();
- const fireToast = useGlobalSnackbarStore((state) => state.fireToast);
-
return useMutation({
mutationFn: logoutFn,
onSuccess: () => {
localStorage.removeItem("accessToken");
queryClient.removeQueries();
- router.push(HOME);
- fireToast("로그아웃이 완료되었습니다");
+ router.refresh();
},
});
};