foamking/middleware.ts
mikl0s efe19f0cda refactor: consolidate protected routes under /intern/*
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 21:53:20 +00:00

26 lines
679 B
TypeScript

import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl
// Don't protect the login page
if (pathname === "/intern/login") {
return NextResponse.next()
}
// Check for session cookie on all /intern/* routes
const sessionCookie = request.cookies.get("session")
if (!sessionCookie?.value) {
const loginUrl = new URL("/intern/login", request.url)
loginUrl.searchParams.set("redirect", pathname)
return NextResponse.redirect(loginUrl)
}
return NextResponse.next()
}
export const config = {
matcher: ["/intern/:path*"],
}