From ebf2fd580ed187bd346e2a81bc022643c1f0280f Mon Sep 17 00:00:00 2001 From: "SK\\ssssk" Date: Sun, 22 Sep 2024 03:16:08 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EA=B5=AC=EA=B8=80=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EB=AA=BB=ED=95=98=EA=B2=8C=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/auth/user/route.ts | 22 +++++++++------ src/app/mypage/page.tsx | 25 ++++++----------- src/app/mypage/profile/page.tsx | 7 +++-- src/app/support/qna/detail/[id]/page.tsx | 5 ++-- src/components/auth/SignIn.tsx | 3 +- src/components/auth/SignUp.tsx | 2 +- src/components/mypage/MyPageUserImage.tsx | 2 +- .../mypage/MyPageUserImageContainer.tsx | 2 +- src/types/UserDto.ts | 28 +++++++++++-------- src/utils/getNewAccessTokenAndRerequest.ts | 7 +++-- 10 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/app/api/auth/user/route.ts b/src/app/api/auth/user/route.ts index 86ab7db5..60748df9 100644 --- a/src/app/api/auth/user/route.ts +++ b/src/app/api/auth/user/route.ts @@ -1,3 +1,4 @@ +import { fetchWithAuth } from "@/utils/fetchWithAuth"; import { cookies } from "next/headers"; import { NextRequest, NextResponse } from "next/server"; @@ -56,15 +57,20 @@ export async function DELETE(request: NextRequest) { return new NextResponse("Refresh token not found", { status: 401 }); } - // 사용자 정보 조회 API - const response = await fetch(`${process.env.BACKEND_URL}/api/users`, { - method: "DELETE", - headers: { - Cookie: `${access_cookie?.name}=${access_cookie?.value}`, - "Content-Type": "application/json", + const url = new URL(request.url); + + // 사용자 삭제 + const response = await fetchWithAuth( + `${process.env.BACKEND_URL}/api/auth/oauth2?type=${url.searchParams.get("type")}`, + { + method: "DELETE", + headers: { + Cookie: `${access_cookie?.name}=${access_cookie?.value}`, + "Content-Type": "application/json", + }, + cache: "no-store", }, - cache: "no-store", - }); + ); if (!response.ok) { return new NextResponse(`${response.statusText}`, { status: response.status }); diff --git a/src/app/mypage/page.tsx b/src/app/mypage/page.tsx index 8f745e8d..93d1bda7 100644 --- a/src/app/mypage/page.tsx +++ b/src/app/mypage/page.tsx @@ -1,7 +1,7 @@ import MyPageHeaderContainer from "@/containers/mypage/MyPageHeaderContainer"; import MyPageMainContainer from "@/containers/mypage/MyPageMainContainer"; import { userResponseDto } from "@/types/UserDto"; -import { fetchWithAuth } from "@/utils/fetchWithAuth"; +import { fetchWithTokenRefreshSSR } from "@/utils/getNewAccessTokenAndRerequest"; import { Metadata } from "next"; import { cookies } from "next/headers"; @@ -11,23 +11,16 @@ export const metadata: Metadata = { }; async function getUserInfo() { - const cookie = cookies().get("access_token"); - const response = await fetchWithAuth( - `${process.env.BACKEND_URL}/api/users/info`, - { - method: "GET", - headers: { - Cookie: `${cookie?.name}=${cookie?.value}`, - }, - }, - ); - if (!response.ok) { - // This will activate the closest 'error.tsx' Error Boundary. - throw new Error(response.statusText); - } + const access_token = cookies().get("access_token"); + const refresh_token = cookies().get("refresh_token"); + const response = await fetchWithTokenRefreshSSR({ + url: `${process.env.BACKEND_URL}/api/users/info`, + accessToken: access_token, + refreshToken: refresh_token, + }); - return response.json() as Promise; + return response; } diff --git a/src/app/mypage/profile/page.tsx b/src/app/mypage/profile/page.tsx index df5c941f..c33443ad 100644 --- a/src/app/mypage/profile/page.tsx +++ b/src/app/mypage/profile/page.tsx @@ -1,4 +1,5 @@ import MyProfileContainer from "@/containers/mypage/MyProfileContainer"; +import { userResponseDto } from "@/types/UserDto"; import { fetchWithTokenRefreshSSR } from "@/utils/getNewAccessTokenAndRerequest"; import { Metadata } from "next"; import { cookies } from "next/headers"; @@ -9,11 +10,13 @@ export const metadata: Metadata = { }; async function getUserInfo() { - return fetchWithTokenRefreshSSR({ + const response = fetchWithTokenRefreshSSR({ accessToken: cookies().get("access_token"), refreshToken: cookies().get("refresh_token"), url: `${process.env.BACKEND_URL}/api/users/info`, }); + + return response; } export default async function page() { @@ -21,7 +24,7 @@ export default async function page() { return (
- +
); } diff --git a/src/app/support/qna/detail/[id]/page.tsx b/src/app/support/qna/detail/[id]/page.tsx index fe05fc1e..628336fc 100644 --- a/src/app/support/qna/detail/[id]/page.tsx +++ b/src/app/support/qna/detail/[id]/page.tsx @@ -1,4 +1,5 @@ import SupportQnADetailEditContainer from "@/containers/support/qna/SupportQnADetailEditContainer"; +import { QnADetailType } from "@/types/QnADto"; import { fetchWithTokenRefreshSSR } from "@/utils/getNewAccessTokenAndRerequest"; import { cookies } from "next/headers"; @@ -22,7 +23,7 @@ async function fetchData(id: number) { const accessToken = cookies().get("access_token"); const refreshToken = cookies().get("refresh_token"); - return fetchWithTokenRefreshSSR({ + return await fetchWithTokenRefreshSSR({ url: `${process.env.BACKEND_URL}/api/qna/${id}`, accessToken: accessToken, refreshToken: refreshToken, @@ -39,7 +40,7 @@ export default async function Page({ params: { id } }: Props) { return (
- +
); } diff --git a/src/components/auth/SignIn.tsx b/src/components/auth/SignIn.tsx index 329d57d2..ac908da0 100644 --- a/src/components/auth/SignIn.tsx +++ b/src/components/auth/SignIn.tsx @@ -59,7 +59,8 @@ const SignIn = () => { 구글로 로그인 */} -
+ +
{ 구글로 1초만에 시작하기 */} -
+

void; onChangeImageUrl: (_: string) => void; diff --git a/src/containers/mypage/MyPageUserImageContainer.tsx b/src/containers/mypage/MyPageUserImageContainer.tsx index 4712c716..a538f92b 100644 --- a/src/containers/mypage/MyPageUserImageContainer.tsx +++ b/src/containers/mypage/MyPageUserImageContainer.tsx @@ -5,7 +5,7 @@ import { useState } from "react"; interface IMyPageUserImageContainer { userImageUrl: string; - userSex: string; + userSex: string | null; } const MyPageUserImageContainer = (props: IMyPageUserImageContainer) => { diff --git a/src/types/UserDto.ts b/src/types/UserDto.ts index 3b722681..db0e3424 100644 --- a/src/types/UserDto.ts +++ b/src/types/UserDto.ts @@ -1,16 +1,20 @@ // Request 요청 결과 Dto +interface UserImage { + id: number; + address: string; + createdDate: string; +} + export interface userResponseDto { - age: number; // 연도 - email: string; id: number; - isAdmin: boolean; + userStatus: string; + userImage: UserImage; nickname: string; - phoneNumber: string; - sex: string; // "male, female" - userImage: { - id: number; - address: string; - createdDate: string; // "2024-07-12", - }; - userStatus: string; // "활성화" | "휴먼" | "삭제" | "관리자" | ""; -} + age: number; + sex: string | null; + email: string; + provider: string; + phoneNumber: string | null; + createdAt: string; + isAdmin: boolean; +} \ No newline at end of file diff --git a/src/utils/getNewAccessTokenAndRerequest.ts b/src/utils/getNewAccessTokenAndRerequest.ts index 17a2e3cb..1eba1356 100644 --- a/src/utils/getNewAccessTokenAndRerequest.ts +++ b/src/utils/getNewAccessTokenAndRerequest.ts @@ -36,7 +36,7 @@ interface IFetchWithTokenRefreshSSR { next?: NextFetchRequestConfig; } -export async function fetchWithTokenRefreshSSR({ +export async function fetchWithTokenRefreshSSR({ accessToken, refreshToken, url, @@ -44,7 +44,7 @@ export async function fetchWithTokenRefreshSSR({ cache, contentType, next, -}: IFetchWithTokenRefreshSSR) { +}: IFetchWithTokenRefreshSSR): Promise { let response = await fetch(url, { method: method || "GET", headers: { @@ -103,5 +103,6 @@ export async function fetchWithTokenRefreshSSR({ throw new Error("API 요청에 실패했습니다."); } - return response; + const data = await response.json(); + return data as T; }