-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from TripInfoWeb/dev
Release: v1.0.3
- Loading branch information
Showing
56 changed files
with
1,246 additions
and
439 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET(request: NextRequest) { | ||
try { | ||
// Query string 파싱 | ||
const url = new URL(request.url); | ||
const code = url.searchParams.get("code"); | ||
|
||
// 백엔드에 액세스 토큰 재요청 | ||
const response = await fetch( | ||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/auth/oauth2/login?type=naver&redirectUrl=${process.env.NEXT_PUBLIC_NAVER_REDIRECT_URL}&code=${code}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
cache: "no-store", | ||
credentials: "include", | ||
}, | ||
); | ||
|
||
const data = await response.json(); | ||
const result = new NextResponse(JSON.stringify(data), { | ||
status: 200, | ||
}); | ||
|
||
if (response.ok) { | ||
const cookies = response.headers.get("set-cookie"); | ||
if (cookies) { | ||
// 받은 쿠키를 파싱하여 설정 | ||
cookies.split(",").forEach((cookie) => { | ||
result.headers.append("Set-Cookie", cookie.trim()); | ||
}); | ||
} | ||
} | ||
|
||
return result; | ||
} catch (error) { | ||
return new NextResponse("서버 에러", { status: 500 }); | ||
} | ||
} | ||
|
||
export async function POST(request: NextRequest) { | ||
try { | ||
// Query string 파싱 | ||
const url = new URL(request.url); | ||
const code = url.searchParams.get("code"); | ||
const body = await request.json(); | ||
|
||
// 백엔드에 액세스 토큰 재요청 | ||
const response = await fetch( | ||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/auth/oauth2/login/kakao?redirectUrl=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URL}&code=${code}`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
createUserInfoRequest: { | ||
...body | ||
} | ||
}), | ||
cache: "no-store", | ||
credentials: "include", | ||
}, | ||
); | ||
|
||
const result = new NextResponse( | ||
response.status == 200 ? "성공" : "실패", | ||
{ | ||
status: response.status, | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
); | ||
|
||
if (response.status == 200) { | ||
const cookies = response.headers.get("set-cookie"); | ||
if (cookies) { | ||
// 받은 쿠키를 파싱하여 설정 | ||
cookies.split(",").forEach((cookie) => { | ||
result.headers.append("Set-Cookie", cookie.trim()); | ||
}); | ||
} | ||
} | ||
|
||
return result; | ||
} catch (error) { | ||
return new NextResponse("서버 에러", { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
function generateRandomString(length: number): string { | ||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
let result = ""; | ||
for (let i = 0; i < length; i++) { | ||
const randomIndex = Math.floor(Math.random() * characters.length); | ||
result += characters[randomIndex]; | ||
} | ||
return result; | ||
} | ||
|
||
export function GET() { | ||
try { | ||
const clientId = process.env.NAVER_CLIENT_ID; | ||
const redirectUri = process.env.NEXT_PUBLIC_NAVER_REDIRECT_URL; | ||
const RANDOM_STATE = generateRandomString(150); | ||
const timestamp = new Date().toISOString(); // Get the current timestamp in ISO format | ||
|
||
if (!clientId || !redirectUri) { | ||
return NextResponse.redirect("/auth/signin"); | ||
} | ||
|
||
const naverAuthUrl = `https://nid.naver.com/oauth2.0/authorize?client_id=${clientId}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&state=${RANDOM_STATE}`; | ||
return NextResponse.redirect(naverAuthUrl); | ||
} catch (error) { | ||
return NextResponse.redirect("/auth/signin"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET(request: NextRequest) { | ||
// const access_cookie = request.cookies.get("access_token"); | ||
// if (!access_cookie) { | ||
// const refresh_cookie = request.cookies.get("refresh_token"); | ||
// if (!refresh_cookie) { | ||
// // 리프레시 토큰이 없으므로 요청 중단 | ||
// return new NextResponse("Refresh token not found", { status: 403 }); | ||
// } | ||
// // 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답 | ||
// return new NextResponse("Refresh token not found", { status: 401 }); | ||
// } | ||
|
||
// // 사용자 정보 조회 API | ||
// const response = await fetch(`${process.env.BACKEND_URL}/api/users/info`, { | ||
// method: "GET", | ||
// headers: { | ||
// Cookie: `${access_cookie?.name}=${access_cookie?.value}`, | ||
// "Content-Type": "application/json", | ||
// "Access-Control-Allow-Origin": "*", | ||
// }, | ||
// cache: "no-store", | ||
// }); | ||
|
||
// if (response.ok) { | ||
// const data = await response.json(); | ||
// return new NextResponse(JSON.stringify(data), { | ||
// status: 200, | ||
// }); | ||
// } | ||
|
||
// if (response.status == 401) { | ||
// return new NextResponse("토큰 만료", { | ||
// status: 401, | ||
// }); | ||
// } | ||
|
||
// cookies().delete("access_token"); | ||
// cookies().delete("refresh_token"); | ||
// return new NextResponse("서버 에러", { | ||
// status: 500, | ||
// }); | ||
} | ||
|
||
export async function PUT(request: NextRequest) { | ||
const access_cookie = request.cookies.get("access_token"); | ||
if (!access_cookie) { | ||
const refresh_cookie = request.cookies.get("refresh_token"); | ||
if (!refresh_cookie) { | ||
// 리프레시 토큰이 없으므로 요청 중단 | ||
return new NextResponse("Refresh token not found", { status: 403 }); | ||
} | ||
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답 | ||
return new NextResponse("Refresh token not found", { status: 401 }); | ||
} | ||
|
||
const requestData = await request.json(); | ||
|
||
// 사용자 정보 조회 API | ||
const response = await fetch(`${process.env.BACKEND_URL}/api/users/info/agree`, { | ||
method: "PUT", | ||
headers: { | ||
Cookie: `${access_cookie?.name}=${access_cookie?.value}`, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(requestData), | ||
cache: "no-store", | ||
}); | ||
|
||
if (response.ok) { | ||
return response; | ||
} | ||
|
||
return new NextResponse("서버 에러", { | ||
status: 500, | ||
}); | ||
} | ||
|
||
export async function DELETE(request: NextRequest) { | ||
// const access_cookie = request.cookies.get("access_token"); | ||
// if (!access_cookie) { | ||
// const refresh_cookie = request.cookies.get("refresh_token"); | ||
// if (!refresh_cookie) { | ||
// // 리프레시 토큰이 없으므로 요청 중단 | ||
// return new NextResponse("Refresh token not found", { status: 403 }); | ||
// } | ||
// // 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답 | ||
// return new NextResponse("Refresh token not found", { status: 401 }); | ||
// } | ||
|
||
// 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", | ||
// }, | ||
// ); | ||
|
||
// if (!response.ok) { | ||
// return new NextResponse(`${response.statusText}`, { | ||
// status: response.status, | ||
// }); | ||
// } | ||
|
||
// cookies().delete("access_token"); | ||
// cookies().delete("refresh_token"); | ||
// return new NextResponse("회원 탈퇴 성공", { | ||
// status: 200, | ||
// }); | ||
} |
Oops, something went wrong.