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 f174e895..93d1bda7 100644 --- a/src/app/mypage/page.tsx +++ b/src/app/mypage/page.tsx @@ -11,21 +11,16 @@ export const metadata: Metadata = { }; async function getUserInfo() { + 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, - }); - - if (!response.ok) { - // This will activate the closest 'error.tsx' Error Boundary. - throw new Error(response.statusText); - } + 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 611b1c58..ac908da0 100644 --- a/src/components/auth/SignIn.tsx +++ b/src/components/auth/SignIn.tsx @@ -44,9 +44,9 @@ const SignIn = () => { 카카오로 로그인 - @@ -58,8 +58,9 @@ const SignIn = () => { /> 구글로 로그인 - -
+ */} + +
{ 카카오로 1초만에 시작하기 - @@ -60,7 +60,7 @@ const SignUp = () => { 구글로 1초만에 시작하기 - + */}

void; onChangeImageUrl: (_: string) => void; diff --git a/src/containers/mypage/MyPageUserImageContainer.tsx b/src/containers/mypage/MyPageUserImageContainer.tsx index 6c244a89..ff3fabc3 100644 --- a/src/containers/mypage/MyPageUserImageContainer.tsx +++ b/src/containers/mypage/MyPageUserImageContainer.tsx @@ -6,7 +6,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; }