- 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.
27 lines
953 B
TypeScript
27 lines
953 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import { cookies } from 'next/headers'
|
|
import type { NextRequest } from 'next/server'
|
|
import { getIronSession } from 'iron-session'
|
|
import { sessionOptions } from './libs/session'
|
|
import type { SessionData } from './types/Auth'
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
const cookieStore = await cookies()
|
|
const session = await getIronSession<SessionData>(cookieStore, sessionOptions)
|
|
|
|
// todo: 로그인 기능 추가 시 주석 해제
|
|
// if (!session.isLoggedIn) {
|
|
// return NextResponse.redirect(new URL('/login', request.url))
|
|
// }
|
|
|
|
return NextResponse.next()
|
|
}
|
|
|
|
// Apply the middleware to all pages except:
|
|
// 1. /dashboard (exclude this specific route)
|
|
// 2. /admin/* (exclude all routes under /admin)
|
|
// 3. /_next/* (exclude Next.js static and image assets)
|
|
export const config = {
|
|
matcher: ['/((?!login|assets).*)', '/((?!_next/static|_next/image|favicon.ico).*)'],
|
|
}
|