-
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 #147 from TripInfoWeb/dev_auth
쿠키가 저장이 되지 않는 문제 SSR로 변경해서 되는지 테스트
- Loading branch information
Showing
2 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
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,43 @@ | ||
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 backendResponse = await fetch( | ||
`${process.env.NEXT_PUBLIC_BACKEND_URL}/api/auth/oauth2/login?type=kakao&redirectUrl=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URL}&code=${code}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
credentials: "include", | ||
}, | ||
); | ||
|
||
const result = new NextResponse( | ||
backendResponse.status == 200 ? "성공" : "실패", | ||
{ | ||
status: backendResponse.status, | ||
headers: { "Content-Type": "application/json" }, | ||
}, | ||
); | ||
|
||
if (backendResponse.status == 200) { | ||
const cookies = backendResponse.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