Skip to content

Commit eb2faba

Browse files
committed
Merge pull request devping-kr#152 from devping-kr/THKV-155
Fix[THKV-155]: 설문 응답페이지 미들웨어 수정
1 parent 8b7e61e commit eb2faba

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

src/middleware.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,34 @@ export const config = {
88
],
99
};
1010

11-
const publicRoutes = [
12-
AUTH_LINKS.signup,
13-
AUTH_LINKS.login,
14-
ROUTES.SURVEY.TAKE,
15-
ROUTES.LANDING,
16-
];
11+
const publicRoutes = [AUTH_LINKS.signup, AUTH_LINKS.login, ROUTES.LANDING];
12+
1713
const publicRoutePatterns = [/^\/survey\/take\/[^/]+$/];
1814

1915
export function middleware(request: NextRequest) {
2016
const isLogin = request.cookies.get('isLogin');
2117
const currentPath = request.nextUrl.pathname;
2218

23-
const isPublicRoute =
24-
publicRoutes.includes(currentPath) ||
25-
publicRoutePatterns.some((pattern) => pattern.test(currentPath));
19+
const isPublicRoute = publicRoutes.includes(currentPath);
2620

27-
if (!isLogin && !isPublicRoute) {
21+
if (
22+
!isLogin &&
23+
!isPublicRoute &&
24+
!publicRoutePatterns.some((pattern) => pattern.test(currentPath))
25+
) {
2826
const url = request.nextUrl.clone();
2927
url.pathname = AUTH_LINKS.login;
3028
return NextResponse.redirect(url);
3129
}
3230

33-
if (isLogin && publicRoutes.includes(currentPath)) {
31+
if (
32+
!isLogin &&
33+
publicRoutePatterns.some((pattern) => pattern.test(currentPath))
34+
) {
35+
return NextResponse.next();
36+
}
37+
38+
if (isLogin && isPublicRoute) {
3439
const url = request.nextUrl.clone();
3540
url.pathname = NAV_LINKS[0].href;
3641
return NextResponse.redirect(url);

0 commit comments

Comments
 (0)