18 lines
601 B
TypeScript
18 lines
601 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export function middleware(req: NextRequest) {
|
|
const url = req.nextUrl.clone();
|
|
const isPublic = url.pathname.startsWith("/login") || url.pathname.startsWith("/_next") || url.pathname.startsWith("/api") || url.pathname.startsWith("/favicon");
|
|
if (isPublic) return NextResponse.next();
|
|
const cookie = req.cookies.get("demoUser")?.value;
|
|
if (!cookie) {
|
|
const redirect = NextResponse.redirect(new URL("/login", req.url));
|
|
return redirect;
|
|
}
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/:path*"],
|
|
};
|
|
|