diff --git a/middleware.ts b/middleware.ts index efac41c..add9b53 100644 --- a/middleware.ts +++ b/middleware.ts @@ -7,18 +7,21 @@ type Session = { user: { id: string; email: string } } export async function middleware(request: NextRequest) { const { pathname } = request.nextUrl - const isPublic = PUBLIC_PATHS.some((p) => pathname.startsWith(p)) + + if (PUBLIC_PATHS.some((p) => pathname.startsWith(p))) { + return NextResponse.next() + } const { data: session } = await betterFetch('/api/auth/get-session', { baseURL: `http://localhost:${process.env.PORT ?? 3000}`, headers: { cookie: request.headers.get('cookie') ?? '' }, }) - if (!session && !isPublic) { + if (!session) { return NextResponse.redirect(new URL('/login', request.url)) } - if (session && pathname === '/login') { + if (pathname === '/login') { return NextResponse.redirect(new URL('/dashboard', request.url)) }