refactor: Update middleware and EdgeProvider for session handling

- Modified middleware matcher to exclude additional routes for improved session management.
- Added login redirection logic in EdgeProvider to ensure users are redirected to the login page if not authenticated.
This commit is contained in:
yoosangwook 2025-05-22 17:08:54 +09:00
parent c76526bf9b
commit a5696984fc
2 changed files with 7 additions and 1 deletions

View File

@ -22,5 +22,5 @@ export async function middleware(request: NextRequest) {
// 2. /admin/* (exclude all routes under /admin)
// 3. /_next/* (exclude Next.js static and image assets)
export const config = {
matcher: ['/((?!dashboard|login|admin|api|_next/static|_next/image|favicon.ico).*)'],
matcher: ['/((?!login|assets).*)', '/((?!_next/static|_next/image|favicon.ico).*)'],
}

View File

@ -74,6 +74,12 @@ export default function EdgeProvider({ children, sessionData }: EdgeProviderProp
router.push('/')
}
}
if (pathname === '/') {
if (!session?.isLoggedIn) {
router.push('/login')
}
}
//alert 함수 변경해서 바인딩
window.alert = function (msg, alertBtn = () => setAlert(false)) {
alertFunc(msg, alertBtn)