-
Notifications
You must be signed in to change notification settings - Fork 3
fix(web): 로그인 미들웨어 안정화 및 홈 메타 타이틀 정비 #499
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import type { NextRequest } from "next/server"; | ||
| import { NextResponse } from "next/server"; | ||
| import { isTokenExpired } from "@/utils/jwtUtils"; | ||
|
|
||
| const loginNeedPages = ["/mentor", "/my", "/community"]; // 로그인 필요페이지 | ||
| const NEED_LOGIN_COOKIE_KEY = "isNeedLogin"; | ||
| const blockedExactPaths = new Set([ | ||
| "/database.php", | ||
| "/db.php", | ||
|
|
@@ -26,11 +28,43 @@ const isProbePath = (pathname: string) => { | |
| return blockedPathPrefixes.some((prefix) => pathname.startsWith(prefix)); | ||
| }; | ||
|
|
||
| const buildLoginRedirectResponse = ( | ||
| request: NextRequest, | ||
| options: { | ||
| clearRefreshToken?: boolean; | ||
| } = {}, | ||
| ) => { | ||
| const { clearRefreshToken = false } = options; | ||
| const redirectUrl = request.nextUrl.clone(); | ||
| redirectUrl.pathname = "/login"; | ||
| redirectUrl.search = ""; | ||
|
|
||
| const response = NextResponse.redirect(redirectUrl); | ||
| response.cookies.set({ | ||
| name: NEED_LOGIN_COOKIE_KEY, | ||
| value: "true", | ||
| path: "/", | ||
| sameSite: "lax", | ||
| maxAge: 60, | ||
|
Comment on lines
+43
to
+48
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.
Useful? React with 👍 / 👎. |
||
| }); | ||
|
|
||
| if (clearRefreshToken) { | ||
| response.cookies.set({ | ||
| name: "refreshToken", | ||
| value: "", | ||
| path: "/", | ||
| expires: new Date(0), | ||
| maxAge: 0, | ||
| }); | ||
| } | ||
|
|
||
| return response; | ||
| }; | ||
|
|
||
| export function middleware(request: NextRequest) { | ||
| const url = request.nextUrl.clone(); | ||
| const pathname = url.pathname; | ||
| const pathname = request.nextUrl.pathname; | ||
|
|
||
| if (pathname === "/robots.txt" && isStageHostname(url.hostname)) { | ||
| if (pathname === "/robots.txt" && isStageHostname(request.nextUrl.hostname)) { | ||
| return new NextResponse("User-agent: *\nDisallow: /\n", { | ||
| status: 200, | ||
| headers: { | ||
|
|
@@ -64,9 +98,11 @@ export function middleware(request: NextRequest) { | |
| }); | ||
|
|
||
| if (needLogin && !refreshToken) { | ||
| url.pathname = "/login"; | ||
| url.searchParams.delete("reason"); | ||
| return NextResponse.redirect(url); | ||
| return buildLoginRedirectResponse(request); | ||
| } | ||
|
|
||
| if (needLogin && isTokenExpired(refreshToken ?? null)) { | ||
| return buildLoginRedirectResponse(request, { clearRefreshToken: true }); | ||
| } | ||
|
|
||
| return NextResponse.next(); | ||
|
|
||
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.
This change removes
<SiteFooter />from the home page render, butapps/web/src/app/(home)/_ui/SiteFooter/index.tsxis still the only place that exposes the site's business information; after this commit that footer is no longer reachable anywhere inapps/web/src/app. This is a user-facing regression from the previous behavior and can hide required disclosure content on the main entry page.Useful? React with 👍 / 👎.