Skip to content

Commit

Permalink
Merge pull request #109 from jeiltodo/temp/common-client
Browse files Browse the repository at this point in the history
fix: middleware 및 next.config.js 수정
  • Loading branch information
Dragonite-Lee authored Aug 22, 2024
2 parents 1cea729 + c97d235 commit 796c816
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/admin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ COPY --from=builder /app/apps/admin/.next ./.next
COPY --from=builder /app/apps/admin/public ./public
COPY --from=builder /app/apps/admin/package.json ./package.json
COPY --from=builder /app/packages ./packages
COPY --from=builder /app/apps/admin/next.config.js ./next.config.js
COPY --from=builder /app/node_modules ./node_modules

EXPOSE 3001
Expand Down
7 changes: 3 additions & 4 deletions apps/admin/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextRequest } from 'next/server';

export function middleware(request: NextRequest) {
const token = request.cookies.get('accessToken')?.value;

console.log('Middleware running');
console.log('Request URL:', request.nextUrl.pathname);
console.log('Token:', token);
Expand All @@ -12,18 +12,17 @@ export function middleware(request: NextRequest) {
if (request.nextUrl.pathname === '/') {
if (!token) {
console.log('Redirecting to /login');
return NextResponse.redirect(new URL('/login', request.url));
return NextResponse.redirect(new URL('/admin/login', request.url));
}
}

//로그인을 해서 토큰이 있으면 login페이지로 못가도록 홈페이지로 리다이렉트
if (request.nextUrl.pathname === '/login') {
if (token) {
console.log('Redirecting to /');
return NextResponse.redirect(new URL('/', request.url));
return NextResponse.redirect(new URL('/admin', request.url));
}
}

}

//특정 path로만 해당 미들웨어가 동작
Expand Down

0 comments on commit 796c816

Please sign in to comment.