-
Notifications
You must be signed in to change notification settings - Fork 0
feat: proxy(middleware) 설정 추가 #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 { NextRequest, NextResponse } from 'next/server'; | ||
|
|
||
| export default async function proxy(request: NextRequest) { | ||
| const accessToken = request.cookies.get('accessToken'); | ||
| const refreshToken = request.cookies.get('refreshToken'); | ||
|
|
||
| const protectedPaths = ['/mypage', '/post-meetup', '/message', '/schedule']; | ||
| const isProtected = protectedPaths.some((path) => request.nextUrl.pathname.startsWith(path)); | ||
|
|
||
| // 보호되지 않은 경로는 그냥 통과 | ||
| if (!isProtected) { | ||
| return NextResponse.next(); | ||
| } | ||
|
|
||
| // 둘 다 없으면 로그인 | ||
| if (!accessToken && !refreshToken) { | ||
| const loginUrl = new URL('/login', request.url); | ||
| loginUrl.searchParams.set('error', 'unauthorized'); | ||
| loginUrl.searchParams.set('path', request.nextUrl.pathname); | ||
| return NextResponse.redirect(loginUrl); | ||
| } | ||
|
|
||
| // accessToken 있으면 통과 | ||
| return NextResponse.next(); | ||
| } | ||
|
|
||
| export const config = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 경로들은 위의 프록시에서 제외되는 건가요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 맞아용 |
||
| matcher: ['/((?!api|_next/static|_next/image|favicon.ico|login|signup).*)'], | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인증 로직에 불일치와 토큰 갱신 로직이 누락되었습니다.
현재 로직의 문제점:
!accessToken && !refreshToken은 둘 중 하나라도 존재하면 24번 줄로 진행합니다. 하지만 23번 줄의 주석은 "accessToken 있으면 통과"라고 명시하고 있어 의도가 불명확합니다.미들웨어에서 토큰 갱신을 처리하거나, 최소한 accessToken이 있을 때만 통과하도록 로직을 명확히 해야 합니다.
🔎 제안하는 수정 (옵션 1: accessToken 필수)
🔎 제안하는 수정 (옵션 2: refreshToken으로 갱신 시도)
refreshToken이 있지만 accessToken이 없는 경우 토큰 갱신을 시도하는 로직을 추가할 수 있습니다. 다만 미들웨어에서 API 호출을 수행하면 복잡도가 증가하므로, 클라이언트 측에서 처리하는 것이 더 나을 수 있습니다.
📝 Committable suggestion