# Next.js Middleware 및 Auth (React / Next.js) > Middleware, NextAuth.js, JWT, 세션 관리, 보호된 라우트, RBAC - 22 면접 질문 - Mid-Level - [면접 질문: React / Next.js](https://sharpskill.dev/ko/technologies/react-next/interview-questions.md) ## 1. Next.js에서 middleware란 무엇인가요? **답변** Next.js middleware는 요청이 처리되기 전에 실행되는 코드로, 응답을 수정하거나 리다이렉트하거나 headers를 추가하거나 접근을 차단할 수 있습니다. 최적의 성능을 위해 Edge Runtime에서 실행됩니다. 일반적으로 인증, 지리적 위치 확인 또는 logging에 사용됩니다. ## 2. App Router를 사용하는 Next.js 프로젝트에서 middleware 파일은 어디에 배치하나요? **답변** middleware.ts(또는 .js) 파일은 app 폴더와 같은 레벨인 프로젝트 루트에 배치해야 합니다. Next.js는 이 파일을 자동으로 감지하고 모든 라우트에 대해 실행합니다. 프로젝트가 해당 구조를 사용하는 경우 src 폴더에 배치할 수도 있습니다. ## 3. middleware가 실행되는 라우트를 어떻게 정의하나요? **답변** middleware의 matcher 설정을 사용하면 경로 패턴을 통해 해당 라우트를 지정할 수 있습니다. 기본적으로 middleware는 정적 파일을 제외한 모든 라우트에서 실행됩니다. matcher는 대상 라우트를 정밀하게 제어하기 위해 wildcards와 regex를 지원합니다. ## 19개 추가 질문 이용 가능 - 인증에 NextAuth.js를 사용하는 주요 장점은 무엇인가요? - Next.js middleware로 라우트를 보호하는 방법은 무엇인가요? 무료로 가입하기: https://sharpskill.dev/ko/login ## 기타 React / Next.js 면접 주제 - [JavaScript 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/javascript-essentials.md): 25개 질문, Junior - [React 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-fundamentals.md): 20개 질문, Junior - [React Hooks](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-hooks.md): 22개 질문, Junior - [컴포넌트 라이프사이클](https://sharpskill.dev/ko/technologies/react-next/interview-questions/component-lifecycle.md): 18개 질문, Junior - [React Router](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-router.md): 20개 질문, Junior - [Context를 활용한 상태 관리](https://sharpskill.dev/ko/technologies/react-next/interview-questions/state-management-context.md): 18개 질문, Junior - [폼과 Controlled Components](https://sharpskill.dev/ko/technologies/react-next/interview-questions/forms-controlled-components.md): 20개 질문, Mid-Level - [데이터 가져오기 및 API](https://sharpskill.dev/ko/technologies/react-next/interview-questions/fetching-data-api.md): 20개 질문, Mid-Level - [React Query (TanStack Query)](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-query-tanstack.md): 20개 질문, Mid-Level - [Styling & CSS-in-JS](https://sharpskill.dev/ko/technologies/react-next/interview-questions/styling-css-in-js.md): 18개 질문, Mid-Level - [Next.js 기초](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-fundamentals.md): 25개 질문, Mid-Level - [TypeScript와 React](https://sharpskill.dev/ko/technologies/react-next/interview-questions/typescript-react.md): 20개 질문, Mid-Level - [Next.js 데이터 페칭](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-data-fetching.md): 24개 질문, Mid-Level - [Next.js Server Actions](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-server-actions.md): 20개 질문, Mid-Level - [Next.js 라우팅 및 내비게이션](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-routing-navigation.md): 22개 질문, Mid-Level - [Next.js API Routes](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-api-routes.md): 20개 질문, Mid-Level - [Next.js Metadata & SEO](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-metadata-seo.md): 18개 질문, Mid-Level - [React 테스트](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-testing.md): 20개 질문, Mid-Level - [Zustand State Management](https://sharpskill.dev/ko/technologies/react-next/interview-questions/zustand-state-management.md): 18개 질문, Mid-Level - [React 성능 최적화](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-performance-optimization.md): 22개 질문, Senior - [Error Boundaries & 에러 핸들링](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-error-boundaries.md): 18개 질문, Senior - [Advanced React Patterns](https://sharpskill.dev/ko/technologies/react-next/interview-questions/advanced-react-patterns.md): 20개 질문, Senior - [Next.js 고급 기능](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-advanced-features.md): 24개 질문, Senior - [Next.js 배포 및 프로덕션](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-deployment-production.md): 20개 질문, Senior - [아키텍처 & 디자인 패턴](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-architecture-patterns.md): 22개 질문, Senior - [React Server Components](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-server-components.md): 26개 질문, Senior - [Next.js 국제화](https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-internationalization.md): 20개 질문, Senior - [React 보안 & 모범 사례](https://sharpskill.dev/ko/technologies/react-next/interview-questions/react-security-best-practices.md): 22개 질문, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ko/technologies/react-next/interview-questions/nextjs-middleware-auth