Skip to content

Commit

Permalink
chore: 구글 로그인 못하게 주석처리 및 타입 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ssssksss committed Sep 21, 2024
1 parent 25e7e9f commit ebf2fd5
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 47 deletions.
22 changes: 14 additions & 8 deletions src/app/api/auth/user/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fetchWithAuth } from "@/utils/fetchWithAuth";
import { cookies } from "next/headers";
import { NextRequest, NextResponse } from "next/server";

Expand Down Expand Up @@ -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 });
Expand Down
25 changes: 9 additions & 16 deletions src/app/mypage/page.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<userResponseDto>({
url: `${process.env.BACKEND_URL}/api/users/info`,
accessToken: access_token,
refreshToken: refresh_token,
});

return response.json() as Promise<userResponseDto>;
return response;
}


Expand Down
7 changes: 5 additions & 2 deletions src/app/mypage/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,19 +10,21 @@ export const metadata: Metadata = {
};

async function getUserInfo() {
return fetchWithTokenRefreshSSR({
const response = fetchWithTokenRefreshSSR<userResponseDto>({
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() {
const userInfo = await getUserInfo();

return (
<div className={"min-h-[calc(100vh-25rem)] w-full px-[.5rem] pb-[2.5rem]"}>
<MyProfileContainer userInfo={await userInfo.json()} />
<MyProfileContainer userInfo={userInfo} />
</div>
);
}
5 changes: 3 additions & 2 deletions src/app/support/qna/detail/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<QnADetailType>({
url: `${process.env.BACKEND_URL}/api/qna/${id}`,
accessToken: accessToken,
refreshToken: refreshToken,
Expand All @@ -39,7 +40,7 @@ export default async function Page({ params: { id } }: Props) {

return (
<main className="mb-8 w-full">
<SupportQnADetailEditContainer data={await data.json()} />
<SupportQnADetailEditContainer data={data} />
</main>
);
}
3 changes: 2 additions & 1 deletion src/components/auth/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const SignIn = () => {
</div>
<span className="text-sm font-semibold text-black">구글로 로그인</span>
</Link> */}
<div className={"relative flex w-full justify-center mt-[2.25rem]"}>

<div className={"relative flex w-full justify-center mt-[3rem]"}>
<div className={"absolute top-[-.5rem] flex flex-col items-center"}>
<div
className={
Expand Down
2 changes: 1 addition & 1 deletion src/components/auth/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const SignUp = () => {
구글로 1초만에 시작하기
</span>
</Link> */}
<div className={"relative flex w-full justify-center mt-[2.25rem]"}>
<div className={"relative flex w-full justify-center"}>
<p
className={
"relative flex w-full justify-center font-semibold text-black"
Expand Down
2 changes: 1 addition & 1 deletion src/components/mypage/MyPageUserImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface IMyPageUserImage {
dragAndDrop: dragAndDropProps;
imageBase64Data: string;
userImageUrl: string;
userSex: string;
userSex: string | null;
isModalOpen: boolean;
closeCropModal: () => void;
onChangeImageUrl: (_: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/containers/mypage/MyPageUserImageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from "react";

interface IMyPageUserImageContainer {
userImageUrl: string;
userSex: string;
userSex: string | null;
}

const MyPageUserImageContainer = (props: IMyPageUserImageContainer) => {
Expand Down
28 changes: 16 additions & 12 deletions src/types/UserDto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 4 additions & 3 deletions src/utils/getNewAccessTokenAndRerequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ interface IFetchWithTokenRefreshSSR {
next?: NextFetchRequestConfig;
}

export async function fetchWithTokenRefreshSSR({
export async function fetchWithTokenRefreshSSR<T>({
accessToken,
refreshToken,
url,
method,
cache,
contentType,
next,
}: IFetchWithTokenRefreshSSR) {
}: IFetchWithTokenRefreshSSR): Promise<T> {
let response = await fetch(url, {
method: method || "GET",
headers: {
Expand Down Expand Up @@ -103,5 +103,6 @@ export async function fetchWithTokenRefreshSSR({
throw new Error("API 요청에 실패했습니다.");
}

return response;
const data = await response.json();
return data as T;
}

0 comments on commit ebf2fd5

Please sign in to comment.