website-builder-frontend/app/middleware.ts

19 lines
497 B
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(req: NextRequest) {
const protectedPaths = ["/dashboard"];
const token = req.cookies.get("firebaseToken");
if (protectedPaths.some((path) => req.nextUrl.pathname.startsWith(path))) {
if (!token) {
return NextResponse.redirect(new URL("/login", req.url));
}
}
return NextResponse.next();
}
export const config = {
matcher: ["/dashboard/:path*"],
};