-
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 #144 from TripInfoWeb/dev_informations
Fix: UI 오류 및 자동 로그인 오류 발생 시 로그인 페이지로 접속할 수 없는 문제 해결
- Loading branch information
Showing
6 changed files
with
46 additions
and
40 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 |
---|---|---|
@@ -1,35 +1,39 @@ | ||
import { cookies } from "next/headers"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const access_cookie = request.cookies.get("access_token"); | ||
if (!access_cookie) { | ||
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 }); | ||
if (!refresh_cookie) { | ||
// 리프레시 토큰이 없으므로 요청 중단 | ||
return new NextResponse("Refresh token not found", { status: 403 }); | ||
} | ||
|
||
// 사용자 정보 조회 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.status === 200) { | ||
const data = await response.json(); | ||
return new NextResponse(JSON.stringify(data), { | ||
status: 200, | ||
}); | ||
} | ||
return new NextResponse("서버 에러", { | ||
status: 500, | ||
// 리프레시 토큰으로 재발급 받아 재요청 보내기 위한 응답 | ||
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.status === 200) { | ||
const data = await response.json(); | ||
return new NextResponse(JSON.stringify(data), { | ||
status: 200, | ||
}); | ||
} | ||
|
||
cookies().delete("access_token"); | ||
cookies().delete("refresh_token"); | ||
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
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
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