From 1981a5937413e27af71e97036c7512017ff3567a Mon Sep 17 00:00:00 2001
From: brian <90752841+wokbjso@users.noreply.github.com>
Date: Sun, 24 Dec 2023 15:34:52 +0900
Subject: [PATCH] =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=B2=98=EB=A6=AC=20?=
=?UTF-8?q?=EC=9E=84=EC=9D=98=20=EB=A1=9C=EC=A7=81=20=EC=83=9D=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.tsx | 53 +++++++++++----------
src/features/auth/queries/dto/auth-login.ts | 9 ++++
src/features/auth/queries/usePostLogin.tsx | 10 ++--
src/pages/auth/Login.tsx | 8 +++-
4 files changed, 52 insertions(+), 28 deletions(-)
diff --git a/src/App.tsx b/src/App.tsx
index a4ac838..02609bc 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -14,33 +14,38 @@ import VoteLeader from "./pages/vote/VoteLeader";
import VoteResults from "./pages/vote/VoteResults";
import VoteDemoday from "./pages/vote/VoteDemoday";
import { ProtectedRoute } from "./features/auth/components/ProtectedRoute/ProtectedRoute";
+import { Suspense } from "react";
function App() {
- const user = false; //로그인 로직
+ const user = true;
return (
-
-
-
- } />
- }
- >
- } />
- } />
-
- }
- >
- } />
- } />
- } />
- } />
- } />
- } />
-
- } />
-
-
+
+
+
+
+ } />
+ }
+ >
+ } />
+ } />
+
+
+ }
+ >
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+
+ } />
+
+
+
);
}
diff --git a/src/features/auth/queries/dto/auth-login.ts b/src/features/auth/queries/dto/auth-login.ts
index 7e64821..461c29a 100644
--- a/src/features/auth/queries/dto/auth-login.ts
+++ b/src/features/auth/queries/dto/auth-login.ts
@@ -2,3 +2,12 @@ export interface AuthLoginRequest {
email: string;
password: string;
}
+
+export interface AuthLoginResponse {
+ code: number;
+ code_desc: string;
+ data: {
+ accessToken: string;
+ refreshToken: string;
+ };
+}
diff --git a/src/features/auth/queries/usePostLogin.tsx b/src/features/auth/queries/usePostLogin.tsx
index 1590942..ad73da2 100644
--- a/src/features/auth/queries/usePostLogin.tsx
+++ b/src/features/auth/queries/usePostLogin.tsx
@@ -1,10 +1,14 @@
import { useMutation } from "@tanstack/react-query";
import { axiosInstance } from "@/common/libs/axios";
-import { AuthLoginRequest } from "./dto/auth-login";
+import { AuthLoginRequest, AuthLoginResponse } from "./dto/auth-login";
async function postLogin(data: AuthLoginRequest) {
- const res = await axiosInstance.post("/app/auth/login", data);
- return res.data;
+ const res = await axiosInstance.post(
+ "/app/auth/login",
+ data
+ );
+ console.log(data);
+ return res.data.data.accessToken;
}
export function usePostLogin() {
diff --git a/src/pages/auth/Login.tsx b/src/pages/auth/Login.tsx
index f1c640d..4e5b5c6 100644
--- a/src/pages/auth/Login.tsx
+++ b/src/pages/auth/Login.tsx
@@ -5,13 +5,19 @@ import { styled } from "styled-components";
import { FORM_TYPE } from "@/features/form/constant/form-type";
import { usePostLogin } from "@/features/auth/queries/usePostLogin";
import { LoginFormState } from "@/features/form/states/form-data-state";
+import { useEffect } from "react";
export default function Login() {
- const { mutate: postLogin } = usePostLogin();
+ const { mutate: postLogin, data: token } = usePostLogin();
const { isMobile } = MediaQuery();
const loginFormSubmit = (e: LoginFormState) => {
postLogin(e);
};
+ useEffect(() => {
+ if (token) {
+ localStorage.setItem("token", token);
+ }
+ }, [token]);
return (